When I select a row and I click

macupryk

Newcomer
Joined
Sep 27, 2003
Messages
21
Location
Canada
click on modify button?
Public Sub DoModify()
Dim bm As BindingManagerBase = Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember)
===>>> Dim dr As DataRow = CType(bm.Current, DataRowView).Row <<<===
Dim editform As New EditTransOverride(dr)
Dim retval As DialogResult = editform.ShowDialog()
If retval = DialogResult.OK Then
bm.EndCurrentEdit()
Try
Dim substr As String = dr.Item(4)
substr = substr.Substring(0, 2)
ExecOnTransOverride.upd(dr.Item(1), dr.Item(2), dr.Item(3), dr.Item(4), dr.Item(5), dr.Item(6), dr.Item(8), dr.Item(7), DateTime.Now, dr.Item(7), dr.Item(9))
SqlDataAdapter1.Update(ds, "DsTransOverride1")
ds.Tables("DsTransOverride1").AcceptChanges()
MsgBox("Data Inserted Successfully !", MsgBoxStyle.Information, Me.Text)
Catch se As SqlException
MessageBox.Show(se.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
bm.CancelCurrentEdit()
End If
End Sub


An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.windows.forms.dll

Additional information: No value at index -1.
I get an error
===>>> Dim dr As DataRow = CType(bm.Current, DataRowView).Row <<<===
What is going on?
 
That's a pretty worthless post - it tells us nothing. Have you checked that bm.Current is index a DataRowView or that it is even set? That is the problem with CType and why you should use DirectCast - if bm.Current isn't of type DataRowView you would get a casting exception which would be much more informative.
 
Back
Top