G
Guest
Hi
I have a readonly datagrid bound to a relation and a button with the code
below in the click event:
Dim bm As BindingManagerBase =
Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember)
Dim dr As DataRow = CType(bm.Current, DataRowView).Row
Dim intPos As Integer
intPos = bm.Position
dr.Delete()
dr.EndEdit()
If intPos > bm.Count - 1 Then
bm.Position = bm.Count - 1
Else
bm.Position = intPos
End If
Me.DataGrid1.Select(bm.Position)
Try
Me.DataGrid1.Focus()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
It works fine for all datagrid rows except the last one, for which the
following error is thrown by the Me.DataGrid1.Focus() line. Also applied if
use clicks as well:
"index was outside the bounds of the array"
Importantly, the Messagebox in the error trap above is NOT HIT!
Any info. would be most appreciated.
I have a readonly datagrid bound to a relation and a button with the code
below in the click event:
Dim bm As BindingManagerBase =
Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember)
Dim dr As DataRow = CType(bm.Current, DataRowView).Row
Dim intPos As Integer
intPos = bm.Position
dr.Delete()
dr.EndEdit()
If intPos > bm.Count - 1 Then
bm.Position = bm.Count - 1
Else
bm.Position = intPos
End If
Me.DataGrid1.Select(bm.Position)
Try
Me.DataGrid1.Focus()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
It works fine for all datagrid rows except the last one, for which the
following error is thrown by the Me.DataGrid1.Focus() line. Also applied if
use clicks as well:
"index was outside the bounds of the array"
Importantly, the Messagebox in the error trap above is NOT HIT!
Any info. would be most appreciated.