Question

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?

Was it helpful?

Solution

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

OTHER TIPS

I had the same issue without any answer. The easy way is to reload the bindingSource when you press the Cancel button.

You can't do it by BindingSource.CancelEdit. Instead you can unbound your single bound controls such as TextBoxes on edit mode and then if user decides to cancel new entered values , again bind them to bindingsource. otherwise if everything goes well and the user decides to save them, replace old values on BindingList with new ones and persist them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top