No way to know if new row added to DataTable?

S

Stephen

How can I be notified AND have access to the new row when
a new row is added to my table?

It seems that the DataTable RowChanged event is called
when adding a new row BEFORE the row is actually inserted
into the table!

For example

DataTable table = new DataTable("test");
// Add RowChanged handler here
DataRow dr = table.NewRow();
//.. Add stuff to row
table.Rows.Add(dr);

Row changed event fired here but my
DataRowChangeEventHandler looks in table.Rows and
Rows.Count is still 0!

I see that DataTable.Columns supports a CollectionChanged
event which the documentation says is raised when a
column is added or deleted. Why is there not a
corresponding event for the Rows collection?

Thanks
Stephen
 
S

Stephen

Figured it out right after (of course) posting the
question. Obviously I need to add the row to the table
before adding the data to the row if I expect to be
notified by the table that a contained row has changed!.
I still don't understand why there isn't a special event
for new rows being added though.

Stephen
 

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