I've got a form with several textboxes and one datagrid. One business entity can be bound to this form. For example, BO looks like this:
class BO : IEditableObject, INotifyPropertyChanged
{
public string FirstName {get; set;}
public string LastName {get; set}
public BindingList<BO> Relatives {get; set}
// implementation of the interfaces
}
So on the form, FirstName & LastName are bound to the textboxes and Relatives is bound to the grid. Also on the form I have buttons Save and Cancel. On clicking Save button I call IEditableObject.EndEdit() and on clicking Cancel button I call IEditableObject.CancelEdit(). I want CancelEdit() method to reject all changes made by the user, including changes in Relatives which is bound to the grid. So far so good..
BUT The grid control uses CurrencyManager (the grid is Devexpress control actually but it doesn't matter since I believe WinForms control uses it too). And CurrencyManager calls BeginEdit() & EndEdit() for items in Relatives collection every time the user changes the row. So when button Cancel() is clicked only changes in FirstName & LastName will be cancelled because for the child objects in Relatives collection EndEdit() was already called by the grid's underlying CurrencyManger! So, the question - how to prevent CurrencyManager from calling that methods so that I could reject all changes by one call?
Thanks!