We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Problems removing data from the DataSource

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

1 Reply

AD Administrator Syncfusion Team November 21, 2005 09:54 PM UTC

You can avoid this problem by moving off the row if it is the last row before you delete it. int index = GetSelectedRow(); if(index == this.gridDataBoundGrid1.Model.RowCount) this.gridDataBoundGrid1.CurrentCell.MoveUp(); (this.gridDataBoundGrid1.DataSource as ArrayList).RemoveAt( index - 1 ); this.gridDataBoundGrid1.Invalidate(); this.gridDataBoundGrid1.Refresh();

Loader.
Live Chat Icon For mobile
Up arrow icon