How to prevent CurrencyManager from calling BeginEdit () / EndEdit () methods on related objects

I have a form with several text fields and one datagrid. One business object can be attached 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, in the form, FirstName and LastName are tied to text fields, and relatives are tied to the grid. Also on the form I have Save and Cancel buttons. When I click the Save button, I call IEditableObject.EndEdit () and when I click the Cancel button, I call IEditableObject.CancelEdit (). I want the CancelEdit () method to reject all changes made by the user, including changes to the Relatives that are bound to the grid. So far so good ..

BUT Grid control uses CurrencyManager (in fact, grid is Devexpress control, but it doesn’t matter, because I believe that WinForms control also uses). And CurrencyManager calls BeginEdit () and EndEdit () for elements in the Relatives collection every time the user changes the line. Therefore, when you click Cancel (), only changes to FirstName and LastName will be canceled, because for children in the Relatives collection, EndEdit () is already called by a grid based on CurrencyManger! So, the question is - how to prevent CurrencyManager from invoking these methods so that I can reject all changes with one call?

Thank!

+3
source share
2 answers

- IEditableObject -. CurrencyManager ( Winforms) , .

, , , . , BeginEdit, EndEdit CancelEdit .

+2

Bindingsource, EndEdit() CurrentChanged, BeginEdit() CurrencyManager.

BeginEdit .

0

Source: https://habr.com/ru/post/1790732/


All Articles