DavidT_macktool
Well-known member
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
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