Reputation: 4101
I have a listbox like so:
list.DataSource = bindingSource;
list.DisplayMember = "column_name";
Later I would want to get the selected item's ID
from the DataSet
with bindingSource.Current
. I've done this before with bindingNavigator
and bindingSource
, where Current
returns a DataRowView
, so I can cast it and I'm done:
Int32.Parse(((DataRowView)bindingSource.Current)["id"].ToString())
But in this case Current
returns a DataViewManagerListItemTypeDescriptor
object, and I can't cast it.
Any thoughts will be appreciated!
Daniel
Upvotes: 0
Views: 10338
Reputation: 116458
list.SelectedItem
should contain the selected row's DataRowView
. Then you can:
var row = (MyRowType)((DataRowView)list.SelectedItem).Row;
Upvotes: 1