Mitkins
Mitkins

Reputation: 4341

What's the best way to check for errors before leaving a row in a DataGridView

As far as I can tell, the best way to do this is do it in the DataTable.RowChanging event. But what if I want to cancel the action? There is no EventArgs.Cancel option...

Upvotes: 1

Views: 482

Answers (2)

Mitkins
Mitkins

Reputation: 4341

In the case of the DataGridView, if you throw an exception in DataTable.RowChanging, you can handle it in DataGridView.OnError. Setting EventArgs.Cancel to true preserves data entry.

Upvotes: 0

TheSoftwareJedi
TheSoftwareJedi

Reputation: 35196

From the DataTable.RowChanging event handler, you can throw an exception to cancel the change. The exception will be thrown to the piece of code making the change where you can handle it appropriately.

Upvotes: 1

Related Questions