DataTable: ColumnChanged event always fired

  • Thread starter Thread starter Anthony
  • Start date Start date
A

Anthony

Hi,

When I update a datatable through a datagrid the ColumnChanged event
is fired. In this event I check if the new value that the user has
entered is correct and change it if it's not. My problem is when I
change it, the ColumnEvent is fired again. How can I prevent this? I
thought BeginEdit would do the trick but it doesn't seem to work.

I thought of using 'RemoveHandler' and 'AddHandler' but I'm fairly
sure there is a proper solution.

Any suggestions?

Anthony.

Simplified code (if I put 'e.Row.BeginEdit()' or not, it doesn't make
any difference):

Private Sub MyDataTable_ColumnChanged(ByVal sender As Object,
ByVal e As System.Data.DataColumnChangeEventArgs) Handles
MyDataTable.ColumnChanged
If e.Column.ColumnName = "Col1" Then
If e.ProposedValue.ToString.Trim.Length > 0 Then
If e.ProposedValue = "test" Then
e.Row.BeginEdit()
e.Row("Col1") = "test2" 'This fires the event
again
e.Row.EndEdit()
End If
Else
e.Row.CancelEdit()
End If
End If
End Sub
 
Hi Anthony,

Why not only make a togle boolean swicth in that procedure

If it is true, it comes back and you can than only set it to false and after
that exit the procedure.

Cor
 
Back
Top