Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undoing All Changes Since BindingSource's last EndEdit call

Here's the scenario (which uses a BindingSource bound to a DataTable within a DataSet):

  1. A user creates a new address book contact, fills in the First and Last name in data-bound controls.
  2. He presses Apply, whose event handler calls BindingSource.EndEdit().
  3. He then realizes there was a mistake, and adds an email address.
  4. But when he presses Apply, validation fails (invalid email format), so EndEdit() isn't called.
  5. He decides not to make the edit, and presses the Cancel button, whose event handler calls BindingSource.CancelEdit().
  6. But, rather than reverting to the new contact with just a First and Last name and no email, the BindingSource has instead gotten rid of the entire record.

Is there any way to only undo actions since the last time EndEdit() was called? I was under the impression that's how CancelEdit() was supposed to work.

like image 430
Dov Avatar asked Oct 27 '22 03:10

Dov


1 Answers

As an explanation, the DataTable only holds 2 states for a record, the Original and Current. Your request would require multiple states.

To achieve what you want you should flush the changes to the database (eg Adapter.Update(table)) in response to a successful Apply. That promotes your Current to Original and the next Cancel can fall back to that.

This may or may not match your requirements though.

like image 84
Henk Holterman Avatar answered Nov 15 '22 11:11

Henk Holterman