Can't modify DataRow during RowChanged event

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?
 
G

Guest

Sorry, the penultimate paragpraph should read:

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

martin marinov

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
 
G

Guest

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
 
G

Guest

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top