DataGrid detect row changes

D

Doug Bell

Hi
I have a DataGrid that has a DataView as its DataSource.

I need to detect when a New Row is added or when a Row is Deleted so that I
change data in the underlying DataTable.

I found that MyDataGrid_CurrentCellChanged doesn't fire on a deletion or on
a New Row if there was no previous rows.

Can someone advised the simplest way to detect row additions or deletions?

Thanks
 
C

Cor Ligthert [MVP]

Doug

As you are working witht he datagrid, try than to forget change information
from that, try to use the underlying datasource. A change in the datagrid is
not as something is typed (or you should use the textbox for that), however
if there is a rowchange.

It is just more simple to work with the datasource than the cells from the
datagrid.

Cor
 
D

Doug Bell

OK but how do I get a change in the underlying DataTable to trigger an Event
that I can use check and set the (complex) "ID" Column in the DataTable for
the New Row.
 
C

ClayB

Try listening to the underly DataView.ListChanged event. (If the
DataSource is a DataTable, this would probably be
DataTable.DefaultView). There you can check for:

if(e.ListChangedType == ListChangedType.ItemAdded)
{
//...
}

Maybe this will picked out the adding of a new row.

================
Clay Burch
Syncfusion, Inc.
 
C

ClayB

Oops. Sorry for the C# code.

If e.ListChangedType = ListChangedType.ItemAdded Then
'...
End If
====================
Clay Burch
Syncfusion, Inc.
 

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