CancelEdit on bindingsource does not cancel all edited fields of the object

I have a bindingList<T> that every bindlist object implements INotifyPropertyChanged my WinForm, I used a BindingSource and set its data source to bindingList<T> , and then bound some text fields to the properties of each element in a 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 to cancel editing. but when I edit the record and I click the β€œCancel” button, only the last edited field cancels, I want to cancel the whole line and restore all values ​​to the values ​​that exist before editing, how can I do this?

+4
source share
3 answers

To undo changes made to the BindingSources current object, the type contained in the BindingSource must implement the IEditableObject Interface

+2
source

I had the same problem without an answer. A simple way is to reboot the link source when you click Cancel.

0
source

You cannot do this with BindingSource.CancelEdit. Instead, you can disable individual related controls, such as TextBoxes, in edit mode, and then, if the user decides to cancel the newly entered values, bind them to the binding source again. otherwise, if all goes well and the user decides to save them, replace the old values ​​with the BindingList with new ones and save them.

0
source

All Articles