set the focus on a record in the datagrid

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
I have 2 grids on a form and one grid has a column that has a pointer to the record id of the other grid. There is not a true master detail relationship between the 2 grids, but I want the form to behave that way. When a row is highlighted on grid1 I would like grid2 to move to the corresponding record being pointed to by grid1. The pointer I use is the primary key of grid2 so I have tried using Dataset.tablename.Rows.Find(primary key value) to locate the correct record in the dataset. Once that is done I need to set the focus of grid2 to the record I just found. What is my code to do this?

Currently I am trying to do this when F2 is pressed, but I would like to do this on some kind of row change event of grid1.
I can do this with the filter text property, but I like to have all the records of grid2 displayed and the correct record highlighted.

Private Sub Grid1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Grid1.KeyDown

' Check if F2 Key is pressed.

If e.KeyCode = Keys.F2 Then

' Key pressed, Show MsgBox

me.MoveToPart

End If

End Sub



Private Sub MoveToPart()

If Grid1.Columns("part id").Value > 0 Then

partpointer = Grid1.Columns("part id").Value

DsPartDeliveries1.Tables("part").Rows.Find(partpointer)

do something to grid2 to move to this record.

End If

End Sub
 
Solved it like this...

PrivateSub Mouse_UP(ByVal sender AsObject, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DetailGrid.MouseUp
Me.MoveToPart()
EndSub

PrivateSub MoveToPart()
Dim DV As DataView
Dim I AsInteger
If DetailGrid.Columns("detail part id").Value > 0 Then
partpointer = DetailGrid.Columns("detail part id").Value
DV =
New DataView(DsPartDetail1.Tables("part"))
DV.Sort = ("part id")
I = DV.Find(partpointer)
Me.BindingContext(DsPartDetail1, "part").Position = I
EndIf
EndSub

 
Back
Top