列表框中选择的项目给我" System.Data.DataRowView" ,C#的WinForms [英] listbox selected item give me " System.Data.DataRowView" , C# winforms
问题描述
我有ListBox1的 - 它的数据源是一列(产品名称)
I have listbox1 - its datasource is a column (productname).
所以我有ListBox中的一个多选$ C $ 。C>选项
so i have in the listbox a MultiSelection
option.
和IM试图使的MessageBox
所有我所选择的选项,这样的代码:
and im trying to make a MessageBox
for all the option i selected and this the code:
foreach (object selectedItem in listBox1.SelectedItems)
{
MessageBox.Show((selectedItem.ToString() + Environment.NewLine));
}
问题是,即时得到这个值,而不是系统.Data.DataRowView
推荐答案
如何填充列表框(即究竟是什么数据源) ?
How do you populate the listbox (ie what is exactly the datasource)?
从你的评论,我会说一个DataView(和至极包含DataRowView的...)
From your comment I would say a DataView (and wich contains DataRowView...)
所以你刚才需要转换的的SelectedItem
到 DataRowView的
为了获得这个DataRowView的一个值:
So you just need to cast the SelectedItem
into DataRowView
in order to get a value from this DataRowView:
foreach (object selectedItem in listBox1.SelectedItems)
{
DataRowView dr = (DataRowView)selectedItem;
String result = dr["productname"].ToString;
MessageBox.Show(result + Environment.NewLine);
}
这可能属于对这个职位也可能会喜欢VB.Net开发商这个。
The VB.Net developers that could fall on this post could also be interested in this.
这篇关于列表框中选择的项目给我" System.Data.DataRowView" ,C#的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!