Search code examples
c#data-bindinginotifypropertychangedbindingsourcebindinglist

CancelEdit on bindingsource doesn't cancel all edited fields of an object


I have a bindingList<T> that each object of bindinglist implement INotifyPropertyChanged, In my WinForm I used a BindingSource and set datasource of it to BindingList<T> then bind some textbox to properties of each item in BindingList(I use this winform for CRUD operations) :

tbName.DataBindings.Add("Text", myBindingSource, "Name", true);
tbFamily.DataBindings.Add("Text", myBindingSource, "Family", true);

and also i have a button for cancel editing. but when i am editing a record and i click on Cancel button, only last edited field cancel, i want to cancel entire row and all values restore to values that have before edit, how can i do this?


Solution

  • To cancel edits made on the BindingSources Current object, the type contained in the BindingSource needs to implement the IEditableObject Interface