请问一下,我用listbox1控件绑定数据库中三列字段,在listbox中显示3列(分别是院系,层次,专业)然后把我需要的行移到另外一个listbox2,现在我想把listbox2中的第三列即(专业)所有数据赋给一个lable....请问我该怎么做呢???
说得有点乱有人能解决吗??listbox1数据: listbox2数据:
院系 层次 专业 院系 层次 专业
11 12 13 11 12 13
21 22 23 21 22 23
21 22 23
31 32 33
41 42 43然后把
listbox2中的第三列即(专业)13,23绑定到lable中。
是C#的。
说得有点乱有人能解决吗??listbox1数据: listbox2数据:
院系 层次 专业 院系 层次 专业
11 12 13 11 12 13
21 22 23 21 22 23
21 22 23
31 32 33
41 42 43然后把
listbox2中的第三列即(专业)13,23绑定到lable中。
是C#的。
然后赋给label.Text
public static string Allstr = "";int count = listbox2.SelectedItems .Count ;
for (int i = 0; i < count ; i++)
{
Allstr = str + this.listbox2.SelectedItems[i].ToString().Trim();
str = Allstr;
}
this.label1.Text = Allstr;
str = "";
Allstr = "
但是这样是把listbox2三列内容都显示出来了,怎样才能把第三列显示出来呢
{
Label1.Text+=item.Text+",";
}
{
Label1.Text+=item.Text+",";
}
这个能绑定其中的一列吗?
for (int i = 0; i < dt.Rows.Count; i++)
{
lst_DaiXuan_ZhuanYe.Items.Add(dt.Rows[i][0].ToString() + "--" + dt.Rows[i][1].ToString() + "--" + dt.Rows[i][2].ToString());
}
那你直接把dt.Rows[i][2].ToString()拼接起来再赋给label不就可以了?
我试过如果listbox是连接数据库数据时可以像你这样做,但是如果不连接数据库数据的话,好像就。。
改成这个试试。。 string str = "";
string Allstr = ""; for (int i = 0; i < listBox2.SelectedItems.Count; i++)
{
str = listBox2.SelectedItems[i].ToString();
int lastIndex = str.LastIndexOf("--") + 2;
Allstr += str.Substring(lastIndex, str.Length - lastIndex);
}
label1.Text = Allstr;
太感谢你了谢谢。