1 Attachment(s)
[RESOLVED] Which Exception to Use?
I understand the error message, but I am not sure which exception to use as I want to generate my own error message.
Code:
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
Me.Validate()
If RoomSetup.Focus Then
Me.RoomCodesBindingSource.EndEdit()
Me.RoomCodesTableAdapter.Update(Me.RestelDataSet.RoomCodes)
End If
If Accounts.Focus Then
Me.BudgetTypesBindingSource.EndEdit()
Me.BudgetTypesTableAdapter.Update(Me.RestelDataSet.BudgetTypes)
End If
Catch ex As System.Data.ConstraintException
MsgBox("My Own Message of some sort")
End Try
End Sub
As you can see I am using an exception but it seems not to be the correct one as I get the message attached not the one I want.
Any help would be appreciated.
Computerman :)
Re: Which Exception to Use?
The key is the last sentence of the error message. You have to handle the DataError event on the grid.
Private Sub DataGridView1_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
If TypeOf (e.Exception) Is System.Data.ConstraintException Then
MsgBox("My Own Message of some sort")
'tell the grid you handled this error
e.Cancel = True
End If
End Sub
Re: Which Exception to Use?
Many thanks for that. I works perfectly.
Computerman :D