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...
views:
219answers:
2
+1
A:
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.
TheSoftwareJedi
2008-10-29 00:53:38
Hmm. That makes sense - but isn't throwing an exception a costly operation?
Camel
2008-10-29 04:52:25
costly compared to just manipulating a local variable - sure... but are you planning on this happening hundreds of times per second?
TheSoftwareJedi
2008-10-29 13:15:37
A:
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.
Camel
2008-10-29 10:46:50