Thanks in advance for any help.
I'm using VS 2008/C# and binding a local List of helper classes as the DataSource for a DataGridView control. Calling the Remove() method on my List of helper classes fires the CellFormatting event of the DataGridView, which makes sense (a bit). But for some reason, when removing whatever happens to be the DataBoundItem of the last row in the grid (so long as the grid has more than one row) the DataGridView's Rows collection is not updated before this event fires. So, in the CellFormatting event handler, I get an IndexOutOfRangeException as the Rows collection is one too large.
I've tried removing the row using the DataGridView.Rows.Remove() method, and binding using a BindingSource rather than binding the List directly as the data source, both to no avail.
I found a few references to this occurance via Google, but answers were either not forthcoming or said to use a Delete() method on either the DataGridView or the DataGridView.Rows collection - neither of which currently exist.
Sorting does not appear to be the issue either, as performing/not performing a sort results in the same outcome.
The only exception to the "last row" being a problem for removal is if the DataGridView contains only one row - in which case everything works fine.
Hopefully some readers have already tackled this issue and would be willing to help. Thanks again!