如何将项目发送到列表框中的新行 [英] How do I send an item to a new line in the listbox

查看:98
本文介绍了如何将项目发送到列表框中的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码,它将数据库中以listform格式的单元格中的项目发送到lsitbox。

但是当它加载到数据库中时,它会显示在一个长列表中,而不是每个新项目都会转到新行。



可以帮助吗?





I have this code which sends items from a cell in the database which is in listform to a lsitbox.
But when it loads in the database it appears in a long list rather than each new item going to a new line..

Can any one help?


private void ItemCBx_SelectedIndexChanged(object sender, EventArgs e)
{

    Listbox1.Items.Clear();
    MAcon.Open();
    OleDbDataAdapter da = new OleDbDataAdapter("Select Process from [Product Family] Where [Product Name] = @ProductName", MAcon);
    da.SelectCommand.Parameters.AddWithValue("@ProductName", ItemCBx.SelectedItem.ToString());
    DataTable dtbl = new DataTable();
    da.Fill(dtbl);

    if (dtbl.Rows.Count == 1)
    {
        Listbox1.Items.Add(dtbl.Rows[0][0]);
    }
    MAcon.Close();
    Listbox1.Show();
    Listbox1.Text.ToString().Split(',').ToList().ForEach(r => Listbox1.Items.Add(r.Trim()));
    //           Define.SelectedIndex = 1;
}





我尝试过:





What I have tried:

Listbox.Text = Listbox1.Text.Replace(",", Environment.NewLine);

推荐答案

Listbox1.Text.ToString().Split(',').ToList().ForEach(r => Listbox1.Items.Add(r.Trim()));



这样的语句很棒,直到它们不起作用。将其分离为组成部分,并使用调试器确切了解发生的情况。我还建议这段代码应该在前面的 if 子句中。


这篇关于如何将项目发送到列表框中的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆