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

ArgumentOutOfRangeException or StackOverflowException occured when row updated from RowChanged

Hello I get ArgumentOutOfRangeException or StackOverflowException after changing some values from RowChanged handler.

Here is exceptions:

A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

Additional information: Index was out of range. Must be non-negative and less than the size of the collection.

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 Syncfusion.Windows.Forms.Grid.GridScroll.RecalcHiddenRowState(Int32 start, Int32 end)
at Syncfusion.Windows.Forms.Grid.GridControlBase.ModelRowsRangeRemoved(Object sender, GridRangeRemovedEventArgs e)
at Syncfusion.Windows.Forms.Grid.GridModel.OnRowsRemoved(GridRangeRemovedEventArgs e)
at Syncfusion.Windows.Forms.Grid.GridModel.RaiseRowsRemoved(GridRangeRemovedEventArgs e)
at Syncfusion.Windows.Forms.Grid.GridModelRowOperations.OnRangeRemoved(GridRangeRemovedEventArgs e)
catched at Syncfusion.Windows.Forms.Grid.GridModelRowOperations.OnRangeRemoved(GridRangeRemovedEventArgs e) in :line 0
---------------or--------------
An unhandled exception of type 'System.StackOverflowException' occurred in syncfusion.grid.windows.dll


Fatal stack overflow error.


I simulated my issue in code. Try to add new row by editing Text column.
-------------------------------------------------
DataTable myTable;

private void Form1_Load(object sender, System.EventArgs e)
{
myTable = new DataTable("DN_ACCOUNT");
myTable.Columns.Add("ID", typeof(Int32));
myTable.Columns.Add("Text", typeof(String));

myTable.RowChanged += new DataRowChangeEventHandler(myTable_RowChanged);

gridDataBoundGrid1.DataSource = myTable;
}

private void myTable_RowChanged(object sender, DataRowChangeEventArgs e)
{
e.Row["ID"] = 1;
}

2 Replies

RA Rajagopal Syncfusion Team March 27, 2007 08:41 PM UTC

Hi,

The RowChanged event of the DataTable gets trigerred whenever any changes to the datarow is made. So, when you try to set a value to the underlying datasource in this event, causes the event to fire continously for various actions leading to throw exception. To resolve this, you can check for e.Action to be as DataRowAction.Add in the RowChanged event or handle the CurrentCellAcceptedChanges event of the grid to do set the value. Below are the code snippets.

private void gridDataBoundGrid1_CurrentCellAcceptedChanges(object sender, CancelEventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
int textColIndex = this.gridDataBoundGrid1.Binder.NameToColIndex("Text");
if(cc.RowIndex > 0 && cc.ColIndex == textColIndex && this.gridDataBoundGrid1.Binder.IsAddNew)
{
CurrencyManager cm = (CurrencyManager)this.gridDataBoundGrid1.BindingContext[this.gridDataBoundGrid1.DataSource];
DataRow dr = ((DataRowView)cm.Current).Row;
dr["ID"] = 1;
}
}

// or //

private void myTable_RowChanged(object sender, DataRowChangeEventArgs e)
{
if(e.Action == DataRowAction.Add)
{
e.Row["ID"] = 1;
}
}

Let us know if you need any further assistance.
Regards,
Rajagopal


C4 c4p March 28, 2007 06:18 AM UTC

Hello, thanks for reply. It was helpful to me.
But I found the real reason of exception.
If I do something like this:

private void myTable_RowChanged(object sender, DataRowChangeEventArgs e)
{
if(e.Action == DataRowAction.Add)
{
myTable.BeginLoadData();
//e.Row["ID"] = 1;
myTable.EndLoadData();
}
}

I still get ArgumentOutOfRangeException. Why I can't use this functions in RowChanged handler?

Loader.
Live Chat Icon For mobile
Up arrow icon