listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
问题描述
我有 listbox1 - 它的数据源是一列(产品名称).
I have listbox1 - its datasource is a column (productname).
所以我在列表框中有一个 MultiSelection
选项.
so i have in the listbox a MultiSelection
option.
我正在尝试为我选择的所有选项制作一个 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));
}
问题是我得到了这个值System.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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:列表框选择的项目给我"System.Data.DataRowView", C# Winforms


- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01