I bount an event of a dataGrid in WPF so I can keep track if a row was updated.
private void dataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
var text = e.Row.Item as Skill;
}
So my goal is to get the new values of the row if it has been modified but it only returns the old value. When I edit it the second time it returns the new value. Why is that?
Why is that?
The RowEditEnding
event occurs before a row edit is committed or canceled: https://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.roweditending(v=vs.110).aspx.
What you really should do is to implement the IEditableObject interface in your Skill
class and handle the logic in the EndEdit()
method.
The other option would be to explicitly commit the edit in your event handler:
private bool _handle = true;
private void dg2_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
if (_handle)
{
_handle = false;
dg2.CommitEdit();
var text = e.Row.Item as Skill;
//...
_handle = true;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With