Andy Webster

Andy Webster

  • NA
  • 117
  • 0

Determine what was clicked

Jan 19 2010 8:49 AM

I have a form with a data bound DataGridView control, an OK button and a Cancel button. The data source for the grid is a dataset which I load from an XML file when the form loads and save back to the XML file when the user clicks OK.
Everything works fine unless the user is adding a new row and has not completed some mandatory columns but then attempts to click cancel.
Before the click event for the cancel button is fired the datagridview attempts to validate the row being added and fires the datagridview data error event due to the missing mandatory fields.
How can I determine that the user is trying to cancel before the click event for the cancel button has fired? I want to add an if statement into the datagridview dataerror event handler that determines if the user is trying to cancel and if so ignores the error.
How can I determine which control, ie the cancel button, was clicked before the click event has fired?
Thanks in advance for any offers of help with this
Regards
Andy

Answers (4)