Can't synchronize individual controls and a datagridview to the same row

Can't synchronize individual controls and a datagridview to the same row. It was easy to do in vs studio 2003.

When I changed to row in the controls, the row would changed in the datagrid through the currency manager . I used the code

dgrd.CurrentRowIndex = cm.Position

I tried a similar strategy with 2005 with the following code

dgrd.CurrentRow = KSGroupsBindingSource.Current

The 'CurrentRow' property of the DataGridView 'Gets the row containing the current cell.' and hence is read only. I couldn't find another member that was an equivalent.

In the opposite direction, I used the hit test.

Private Sub dgrd_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgrd.MouseDown
Dim myGrid As DataGrid = CType(sender, DataGrid)
Dim hti As System.Windows.Forms.DataGrid.HitTestInfo
hti = myGrid.HitTest(e.X, e.Y)
Dim iRow As Integer
Select Case hti.Type
Case System.Windows.Forms.DataGrid.HitTestType.Cell, System.Windows.Forms.DataGrid.HitTestType.RowHeader
iRow = hti.Row
cm.Position = iRow
Case Else
End Select

End Sub

I tried the following with the datagridview:

Private Sub dgrd_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgrd.MouseDown
Dim myGrid As DataGridView = CType(sender, DataGridView)
Dim hti As System.Windows.Forms.DataGridView.HitTestInfo
hti = myGrid.HitTest(e.X, e.Y)
Dim iRow As Integer
Select Case hti.Type
Case System.Windows.Forms.DataGridView.HitTestType.Cell, System.Windows.Forms.DataGridView.HitTestType.RowHeader
iRow = hti.Row
KSGroupsBindingSource.Position = iRow
Case Else
End Select

End Sub

Trouble is with the hittesttype. There is no Cell or RowHeader, only x,y coordinates. And that's a big job.

Is there a work around for these two problems? It seems a step backward from vs 2003.


dennist

[2023 byte] By [dennist] at [2007-12-16]

.NET Development

Site Classified