Wednesday 28 May 2008

DataGridView - wrong row edited

When using the Edit functionality of a DataGridView it is easy to fall into the trap of selecting the wrong row to edit when running in a multi-user environment.

When user clicks row to edit you must store the ID of the row (not its index), then just prior to data-bind find the index of the selected ID in the data-source and set the EditIndex, this means if another user adds or removes rows in between the the current user clicking edit the correct row will be selected.