Database Programming Techniques > Coordinating with Other Controls |
You can link multiple True DBGrid controls using the RowColChange event to trigger related actions. Whenever the grid's current cell changes, the RowColChange event is fired, indicating that a new row and/or column has become current. RowColChange is triggered in the following cases:
The user clicks on a new row and/or column in the grid.
The current cell is changed by code. This includes changing the grid's Bookmark, Col, or Row properties and changing the current record through the Recordset.
Data in the grid is refreshed.
The user moves the record pointer using the navigation buttons on the Data control associated with the grid.
For example, you can use the RowColChange event to update the display of a status bar that provides additional information or instructions as the user navigates from column to column. By providing the user with clues during the data entry process, you can make your program more intuitive.
Example Title |
Copy Code
|
---|---|
Private Sub TDBGrid1_RowColChange(LastRow As Variant, _ ByVal LastCol As Integer) ' TDBGrid1.Col has the new current column index. Display help string in Label1. Select Case TDBGrid1.Col Case 0 Label1.Caption = "Customer's credit card number" Case 1 Label1.Caption = "Five-digit order number" Case 2 Label1.Caption = "Total cost in US dollars" End Select End Sub |
The RowColChange event is also a convenient place to coordinate activities with other controls or databases. Tutorial 3 provides an example of how you can use the RowColChange event to implement master-detail relationships using two True DBGrid controls.