views:

1597

answers:

1

Hey!

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+bindingSource, 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

A: 

list.SelectedItem should contain the selected row's DataRowView. Then you can:

var row = (MyRowType)((DataRowView)list.SelectedItem).Row;
lc
I tried:((DataRowView)szakList.SelectedItem).Row["id"]and I still get the error that I can't cast from DataViewManagerListItemTypeDescriptor. Am i doing something wrong?:\
wheelie
Sry, i made something wrong, all working fine now:)
wheelie
Oh and forgot, THANK YOU:)
wheelie
No problem. Glad I could help.
lc