I have a need in my application to programatically remove the items from the DataSource of the GDBG.
I''m using follwing code to do that:
private void buttonRemove_Click(object sender, EventArgs e)
{
int index = GetSelectedRow();
(this.gridDataBoundGrid1.DataSource as ArrayList).RemoveAt( index - 1 );
this.gridDataBoundGrid1.Invalidate(); this.gridDataBoundGrid1.Refresh();
}
NOTE: This needs to be done programatically, I can''t use the GDBG build-in delete method.
All works fine till I try to delete the last item from the list. The GDBG loses it mind after that is done. From that point on it will always remove last item from the list even it the other selection in the grid was made. It appears that the grid range selection can not be reset after the removal of the last item.
Also when in this state if the Up or Down arrow is pressed the exception is thrown by the grid.
How can I prevent this problems and still be able to remove the data from the Data Source.
Sample application is attached.
To reproduce the problem:
1. Select Item 8.
2. Press: Remove and then Remove again.
3. Now select Item 5 and press Remove, last Item is removed from the list.
4. Press Up arrow twice and app will crash.
DeleteTest.zip