列表框中选择的项目给我" System.Data.DataRowView" ,C#的WinForms [英] listbox selected item give me " System.Data.DataRowView" , C# winforms

查看:319
本文介绍了列表框中选择的项目给我" System.Data.DataRowView" ,C#的WinForms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ListBox1的 - 它的数据源是一列(产品名称)

I have listbox1 - its datasource is a column (productname).

所以我有ListBox中的一个多选选项

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屋!

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