DataGrid + IEditableObject, does not refresh on CancelEdit - RESOLVED

Dec 4, 2008 at 8:39 AM
Edited Dec 4, 2008 at 9:22 AM
I have a DataGrid that is bound to an ObservableCollection of business objects of a specific type. The business object in question implements IEditableObject, and I have verified that BeginEdit, EndEdit and CancelEdit get called at the appropriate times. However, if I change the value of more than one cell during an editing session, and cancel the row changes (by pressing Escape twice), only the selected sell gets redrawn with the old (now current, verified to be in the business object at the time) information. If I move to one of the previously changed but not redrawn cells and enter edit mode, the correct data does indeed show up.

The implementation of the business object is to have a struct holding the actual information, and properties to expose member variables of the struct in a controlled manner. This is probably where the culprit is, as all I do on CancelEdit is to replace this struct with an old copy saved on BeginEdit, but how do I make the DataGrid realize that it needs to redraw the current row? Or, if redrawing just the current row isn't a possibility, the whole grid? (There won't be enough data in the grid at the same time that redrawing everything is going to be a major issue.) I tried calling dataGrid.UpdateLayout() from within RowEditEnding since that was the closest I could find in IntelliSense, but it didn't appear to change anything.


Edit: declaring the struct member variable "volatile" had no apparent effect.
Dec 4, 2008 at 1:53 PM
Does your business object implement INotifyPropertyChanged? This will let the bound columns know that the underlying object properties have changed after you cancel the edit.
Dec 4, 2008 at 1:58 PM
No, thank you! I knew it was probably simple - I will definitely try this.
Dec 4, 2008 at 3:30 PM
Implementing INotifyPropertyChanged did indeed do the trick. Thank you, peterburrell!