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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Deleting the LAST row from a databoundgrid...

Thread ID:





4756 May 29,2003 03:01 PM UTC May 29,2003 05:32 PM UTC WinForms 1
Tags: GridControl
Administrator [Syncfusion]
Asked On May 29, 2003 03:01 PM UTC

Hi all. 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) at System.Windows.Forms.CurrencyManager.EndCurrentEdit() : : : 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!! Thanks! -Chris

Administrator [Syncfusion]
Replied On May 29, 2003 05:32 PM UTC

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.
int recNumber = this.techGrid.Binder.RowIndexToPosition(curRowIndex);
if(curRowIndex == this.techGrid.Model.RowCount && recNumber >0)
	this.techGrid.Binder.CurrentPosition = recNumber - 1;
this.techGrid.Binder.RemoveRecords(recNumber, recNumber);


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon