I added some validation codes by using the AddHandler for the rowchanging event. The validation is to make sure that one date has to be later than another. When the program was run and I entered an invalid date, the validation was run and I got the error and a box asking if I want to correct the value. I clicked "Yes" and then for some reason the validation was ran a second time and I got a Microsoft Development Environment error ("An unhandled exception of type 'System.Exception' occurred in system.windows.forms.dll. Additional information: Due date must be after request date."). Then I had to "break" or "continue" (but the "continue" really just ended the program). I don't understand why the validation was run a second time (I found out about this when I stepped through the code). I thought when I throw an exception I should be brought back to editing the value. I swear that this was working at one point in time. But now it just does not work and I don't know what causes it. Anyone has any clue?
And, this seems to happen only with new records. When I just updated an existing record, the validation would execute fine.
Here's sample of my code: (Note: Due Date is not a required field; the validation would only take place if the user keys in the due date)
AddHandler dataTable.RowChanging, New DataRowChangeEventHandler(AddressOf Row_Changed)
Private Sub Row_Changed(ByVal sender As Object, ByVal e As DataRowChangeEventArgs)
And, this seems to happen only with new records. When I just updated an existing record, the validation would execute fine.
Here's sample of my code: (Note: Due Date is not a required field; the validation would only take place if the user keys in the due date)
AddHandler dataTable.RowChanging, New DataRowChangeEventHandler(AddressOf Row_Changed)
Private Sub Row_Changed(ByVal sender As Object, ByVal e As DataRowChangeEventArgs)
If e.Action = DataRowAction.Add Or e.Action = DataRowAction.Change Then
If IsDBNull(e.Row("DueDate")) = False Then
If e.Row("DueDate") < e.Row("RequestDate") Then
Throw (New Exception("Due date must be after request date. "))
End If
End If
End IF
End Sub
Last edited: