从绑定到列表框的bindingsource获取行数据
-
03-07-2019 - |
题
我有一个像这样的列表框:
list.DataSource = bindingSource;
list.DisplayMember = "column_name";
稍后我想从 bindingSource.Current
中的 DataSet
中获取所选项目的 ID
。我之前用 bindingNavigator
和 bindingSource
完成了这个,其中 Current
返回 DataRowView
,所以我可以把它投了我已经完成了:
Int32.Parse(((DataRowView)bindingSource.Current)["id"].ToString())
但是在这种情况下 Current
返回 DataViewManagerListItemTypeDescriptor
对象,我无法转换它。
任何想法都将不胜感激!
丹尼尔
解决方案
list.SelectedItem
应包含所选行的 DataRowView
。然后你可以:
var row = (MyRowType)((DataRowView)list.SelectedItem).Row;
不隶属于 StackOverflow