I may be missing something here. The row does get validated as far as
routine non-key fields are concerned. No problem there.
However through trial and error I did find a solution to my problem, in the
DataError handler, which essentially consists of the thing ignoring those
IndexOutOfRangeExceptions I mentioned. Here's the code. Does this make
sense?
Private Sub dgFlowComp_DataError(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles
dgFlowComp.DataError
Dim nReturnCode As Integer = MsgBoxResult.Yes
Dim nDialogStyle As Integer = CType(MsgBoxStyle.YesNo, Integer) +
CType(MsgBoxStyle.Exclamation, Integer)
If TypeOf (e.Exception) Is ConstraintException Then
nReturnCode = MsgBox("Error editing grid, error = " +
e.Exception.Message + ". Do you wish to discard changes?",
CType(nDialogStyle, Microsoft.VisualBasic.MsgBoxStyle), "Warning")
ElseIf Not TypeOf (e.Exception) Is IndexOutOfRangeException Then
MsgBox("Error editing grid, error = " + e.Exception.Message)
End If
If nReturnCode = MsgBoxResult.Yes Then
dgFlowComp.CancelEdit()
End If
e.Cancel = True
End Sub
> Afternoon Chernick,
>
[quoted text clipped - 31 lines]
> > Am I even trying to handle the error in the right place? RowValidating
> > doesn't seem to do anything for index errors.
Brendon Bezuidenhout - 29 Oct 2007 00:06 GMT
Hmmm - With regards to the IndexOutOfRangeException and your BindingSource:
Are you using the AddingNew event or AddNew method on the binding source?
You most likely have just not added the record to the underlying DataSet but
the BindingManager thinks it is there or visa versa...
Sorry I can't be more help :(
Brendon
p.s. - Strings are immutable - use StringBuilder rather for string
concatenation :) it will speed things up and use Messagebox.Show :) rather
than VB6 msgbox *grin* or having to do messy type conversions which "could"
be error prone...
"Messagebox.Show(title, message, buttons, icons)"
>I may be missing something here. The row does get validated as far as
> routine non-key fields are concerned. No problem there.
[quoted text clipped - 69 lines]
>> > Am I even trying to handle the error in the right place? RowValidating
>> > doesn't seem to do anything for index errors.
B. Chernick - 29 Oct 2007 14:42 GMT
My turn to be sorry. I'm not really using anything. This is actually a
rather simple-minded grid. I've just bound it to a binding source and
enabled adding. It's really mostly defaults aside from the DataError code
and a few values added in DefaultValuesNeeded.
> Hmmm - With regards to the IndexOutOfRangeException and your BindingSource:
>
[quoted text clipped - 86 lines]
> >> > Am I even trying to handle the error in the right place? RowValidating
> >> > doesn't seem to do anything for index errors.