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?
Objects are persisted (inserted or updated) when the user leaves a row that he was editing. Moving to another cell in the same row updates the corresponding property through data binding, but doesn't signal the Model (or the Data Access Layer) yet. The only useful event is DataGrid.RowEditEnding. This is fired just before committing the modified row.
XAML
Code Behind
private void MyDataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{ // Only act on Commit
if (e.EditAction == DataGridEditAction.Commit)
{
var newItem = e.Row.DataContext as MyDataboundType;
if (newItem is NOT in my bound collection) ... handle insertion...
}
}
All credits for this solution go to Diederik Krolls (Original Post). My respect.