Trapping exception in rowchanging event.
Posted on 2006-04-13
Hello, I am doing some validation on the rowchanging event of my datagrid which checks to see if certian fields are filled in. If one of the columns in null I throw an exception to cancel the editing. Is there a way to trap this exception and then display one of my own message boxes? I tried using try..catch to trap it and then put my messagebox in the Catch but when doing this I get the error: "error when committing the row to the original data source". Is there a way to get this to work? My code is below.
'check to make sure all required fields are populated
If e.Row.Item("TransDate") Is DBNull.Value Then
e.Row.SetColumnError("TransDate", "Date is a required field")
ElseIf e.Row.Item("TransactionType") Is DBNull.Value Then
e.Row.SetColumnError("TransactionType", "Activity is a required field")
Throw New Exception("Activity is a required field.")
Catch ex As Exception