Getting selected row in dataset

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,530
Location
Lansing, MI; USA
Programming Experience
10+
I have a DataSet made in DesignView with a Listbox bound to it, when the user selects an item in the Listbox and clicks the Rename button, I need to know what row that record is in the DataSet so I can rename an item in that row, what's the best way to do this?

I've tried using the BindingContext form the BindingManagerBase but the count property only shows 1 row at position 0, there are 6 rows (6 items in the ListBox)

I hope I've explained it clear enough, I'm not good with database stuff in VB yet
 
Your listbox should be bound through a BindingSource, which has a .Current property returning you a DataRowView object, which has a .Row property which is the actual row in the datatable in the dataset..

DirectCast(MyBindingSource.Current, DataRowView).Row

Try to avoid ling's method because if the listbox is sorted, then selected index 1 might be showing row 12.
 
Back
Top