Search code examples
c#wpfdatagridwpfdatagrid

How can I know the changed values after cell commited changes on datagrid


My problem, actually I need to know if some especific cell changed on the datagrid rows for auto fill other fields of the same row inmediately with defaults values.

I try with the RowEditEnding event. But this event is fired before the changes are comitted and I need a event after the changes are commited to get the new value of the especific cell.

The question:

How can I know the values of a cell immediately after the cell lost the focus?


Solution

  • It looks like all the *EditEnding events for cells and rows are raised before the changes are committed (and, in fact, the events provide a last chance to cancel the edits).

    If you can wait until the user is done editing the entire row, the most reliable solution would probably be to have your row objects implement IEditableObject and have them fire an event when EndEdit is called. The grid should call CancelEdit or EndEdit when editing is completed, based on whether editing was canceled or committed. Note, however, that this will only be called when the user finished editing the entire row; you wouldn't be notified when the user finishes editing a cell.

    If you are filling in default values when a new row is added, and the row is being added via the "new item row", you could try handling the AddingNewItem event and filling in the default values when the user begins editing. That might be the smoothest approach.

    Alternatively, you could handle CellEditEnding and schedule a deferred operation using Dispatcher.BeginInvoke to fill in the default values for the other columns.