Can't modify DataRow during RowChanged event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I need to trap the insertion of a new row into a DataTable while it is being
filled by a data adaptor. I am trapping the RowChanged event and using the
following syntax to try and modify the row:

e.Row.ItemArray(index) = newValue

The line above executes without errors BUT my change is actually applied to
the DataRow!

What am I doing wrong please?
 
Sorry, the penultimate paragpraph should read:

The line above executes without errors BUT my change is NOT BEING applied to
the DataRow!
 
Hello Amir,

Actually the ItemArray is a copy of the cells' values of the TableRow
the proper code should be e.Ro(index) = newValue

In this case the update should run without problems

Regards
Martin
 
Hi there,

Use Row directly. Also make sure you change the value only when it hass been
added:

protected void table_RowChanged(object sender, DataRowChangeEventArgs e)
{
if (e.Action == DataRowAction.Add)
e.Row[itemIndex] = newValue;
}

Hope it helps
 
Thanks Martin & Milosz - your comments helped me solve the problem.

Milosz Skalecki said:
Hi there,

Use Row directly. Also make sure you change the value only when it hass been
added:

protected void table_RowChanged(object sender, DataRowChangeEventArgs e)
{
if (e.Action == DataRowAction.Add)
e.Row[itemIndex] = newValue;
}

Hope it helps
--
Milosz


Amir Tohidi said:
Sorry, the penultimate paragpraph should read:

The line above executes without errors BUT my change is NOT BEING applied to
the DataRow!
 
Back
Top