RowDeleting, RowChangeing, ColumnChanging exception handling

?

?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?
 
V

Val Mazur

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top