Search code examples
c#wpfdatagrid

WPF DataGrid - Event for New Rows?


I'm using the WPF DataGrid (.Net 3.5 SP 1 version from the Toolkit)

What event can I subscribe to, to detect when a new row is added? (e.g. when the user moves the cursor down or presses Enter a new blank row gets added to the grid).

Eventually what I want to do is use that event to calculate some default values and put them in the new row.

The grid is bound to a DataTable, if that makes any difference.


Solution

  • Instead of working on events within your View (the grid), I'd recommend watching the bound object instead, and putting your logic there. This keeps your business logic with your business objects.

    Since you're bound to a DataTable, the simplest way is to just subscribe to DataTable.TableNewRow.