RowDeleting, RowChangeing, ColumnChanging exception handling

  • Thread starter Thread starter ?eljko Margeta
  • Start date Start date
?

?eljko Margeta

As I figured out, the recomended way to cancel editing of a column, or
deletion of a row is to create an event handler for ColumnChanging or
RowDeleting events, and to throw your own exception. Well, I did just
that, and the problem is that I do not know where to catch this
exception. As I understand, it should be done somewhere in the
DataGrid which is bound to the DataTable which raised an event, but I
don't know where. Can anybody help me?
 
Hi,

What you need to do is to create events for the DataTable and catch all the
changes there. If DataGrid control is bound to the DataTable, then events
will fire for the DataTable as soon as DataGrid will try to change or
delete. Your code would look like


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

myDataTable = New DataTable("myDataTable")
AddHandler myDataTable.RowChanging, AddressOf myDataTable_Changing

End Sub

Protected Sub myDataTable_Changing(ByVal sender As Object, ByVal e As
System.Data.DataRowChangeEventArgs)
e.Row.CancelEdit()
End Sub
 
Back
Top