2

Is there a way I can receive a notification after a WPF DataGrid row has been edited and the changes committed to the underlying object? At this point I want to persist the modified item to disk.

I don't need to know which row was modified, I can find that out myself, I just need the notification that a row has been modified.

I could register a PropertyChanged handler with each object in the model and be notified that way, but apart from having to mess around registering/deregistering event handlers whenever items are added/removed from the collection, a bigger problem is how to handle multiple PropertyChanged events being raised on a row edit. I don't want to be saving the item multiple times.

Weyland Yutani
  • 4,682
  • 1
  • 22
  • 28

1 Answers1

3

Try implementing the IEditableObject interface, which was created for just this purpose. The grid will call EndEdit when the row is done being modified, which I believe is when the row loses focus.

Take a look at this SO question for more information on how the grid interacts with this interface.

I would recommend implementing INotifyPropertyChanged anyway if you plan on updating the grid on a refresh, or otherwise editing values in code. If you want to do updates immediately on a cell update, you could also do it in the property changed handler.

Community
  • 1
  • 1
Matt
  • 2,682
  • 1
  • 17
  • 24