Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF RowEditEnding returns old values

Tags:

c#

wpf

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?

like image 409
Tom el Safadi Avatar asked Oct 17 '25 14:10

Tom el Safadi


1 Answers

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;
    }
}
like image 119
mm8 Avatar answered Oct 19 '25 04:10

mm8



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!