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?