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.
Unfortunately, activation email could not send to your email. Please try again.

Deleting the LAST row from a databoundgrid...

Thread ID:

Created:

Updated:

Platform:

Replies:

4756 May 29,2003 11:01 AM May 29,2003 01:32 PM Windows Forms 1
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On May 29, 2003 11:01 AM

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 01:32 PM

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);

CONFIRMATION

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.

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.

;