Here is what I did:
Use the dataGridView events CellBeginEdit and CellEndEdit to manage things. If you edit and exit an email address cell, it fires the CellEndEdit event.
You should receive a CellEndEdit event and a button click event when one of these buttons is clicked. In my tests, I always got CellEndEdit, but I suppose YMMV.
If CellEndEdit failed, you might not correctly execute the OK / Cancel code.
Alternatively, you can use the CellValidating event and the e.Cancel event if the value is invalid. This will disable the button click event and leave you in an edited cell.
source share