0

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

1 Answer 1

1

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

var row = (MyRowType)((DataRowView)list.SelectedItem).Row;
Sign up to request clarification or add additional context in comments.

1 Comment

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?:\

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.