I'm trying to get my datagridview control to remember the selected row after data refresh.
The DGV is databound to a list of business objects:
Dim FXs As SortableBindingList(Of FX) = FX.LoadAllForBinding(FXStatus)
Dim bs As New BindingSource
bs.DataSource = FXs
The overall sequence is something like this:
- User clicks on a row
- Row index is saved in a variable
- User edits data in pop up form and closes when finished
- Datagridview is refreshed (re-bound from scratch)
Selected row is set to the previously saved index (in DataBindingComplete event of DGV)
Me.dgvMain.Rows(_CurrentSelectedRowNo).Selected = True
This seems to work fine, the selected row is set correctly (at least the count goes from 0 to 1). However what happens next is that the debugger jumps into the properties of the bound business object (presumably reading them for binding), so that DataBindingComplete event seems to fire BEFORE the DataBinding has been done.
The DGV can have up to about 300 rows so it's pretty annoying for the user that it jumps back to row zero each time they edit a row!
Am I doing something obviously wrong here? Should I be using a different event for this?