4

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?

Masoud
  • 8,020
  • 12
  • 62
  • 123

3 Answers3

2

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

TDull
  • 753
  • 5
  • 12
0

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

Luxo
  • 1
0

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.

Vahid Ghadiri
  • 3,966
  • 7
  • 36
  • 45