Search code examples
c#wpfdata-bindingdatagrid

DataGrid CellEditending event does not return the updated value in the cell


I'm trying to get the currently edited and updated item from WPF Datagrid. This is my code:

private void onCellEdit (object sender, DataGridCellEditEndingEventArgs e)
{                
    VML.MyViewModel.CurrentPackage = (MyPackage )e.EditingElement.DataContext;                   
}

Binding Property

Mode=TwoWay, UpdateSourceTrigger=Default

Unfortunately this will return the value before editing the cell, the atttibutes are not updated, values available in the EditingElement.DataContext has older values before editing.

Is there a way I can get the edited value without using selectedrowchange event since it won't work with the last row?


Solution

  • For DataGridTextColumn you can get edited value by this.

    ( e.EditingElement as TextBox ).Text