I am having a problem deleting the last row in a GridDataBoundGrid. Specifically: When I attempt to delete the last row in the grid through code, the row appears to delete. But, when I then click another row in the grid, the application appears to "freeze" for a moment, then an exception occurs (1st couple of lines of stack trace):
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
BUT, if I delete any other row except for the last row, everything runs fine. I don't understand this at all. I've included a ver small project (Visual Studio .NET 2003) that demonstrates this. Any ideas on what I'm doing wrong would be greatly appreciated!!
The problem is because the current binder position is being left on the last row, and the last row is being removed (making the current position invalid).
Until we can get this fixed, you can avoid the problem with a simple check to correct the position if you are deleting the last row.