Results 1 to 4 of 4

Thread: [RESOLVED] CancelEdit BindingSource need help

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    528

    Resolved [RESOLVED] CancelEdit BindingSource need help

    I have a form with a DataGridView that is bound to a DataTable via a BindingSource. The form also has a button, located below the grid, named btnCancel. This button calls the BindingSource.CancelEdit method.

    When I edit a cell in the grid and before I move to a different row in the grid, I can cancel the pending changes to the row via the ESC key. When the ESC key is clicked, the prior values of all cells in the row are restored to the grid.

    When I click the btnCancel button, this does not happen. The prior values of all cells in the row are not restored to the grid. I suspect that this is because by clicking the button I've left the DataGridView and its BindingSource.EndEdit method is implicitly called. When I inspect the row of the DataTable its RowState is Modified and it does not have a Proposed DataRowVersion.

    If the btnCancel_Click event calls the DataTable.RejectChanges method instead of the BindingSource.CancelEdit method, then all pending changes to all rows/cells are canceled and the prior values are restored to the grid.

    How would I use the btnCancel button to mimic the ESC key to cancel the changes to the current row of the grid?

    Thanks in advance for any suggestions.
    Last edited by Mark@SF; Aug 19th, 2019 at 02:09 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width