How to: Set Up a One-to-Many Form Using the Grid Control
|Visual FoxPro 9.0 SP2|
|How to: Set Up a One-to-Many Form Using the Grid Control|
One of the most common uses for a grid is to display the child records for a table while text boxes display the data for the parent records. When the user moves through the records in the parent table, the grid displays the appropriate child records.
If you have a data environment for your form that includes a one-to-many relationship between two tables, displaying the one-to-many relationship in the form is very easy.
To set up a one-to-many form with a data environment
Drag desired fields from the parent table in theto your form.
Drag the related table from the Data Environment Designer to the form.
In almost all cases, you will want to create a data environment for your form or form set. However, it is not much more complicated to create a one-to-many form without using the Data Environment Designer.
To set up a one-to-many form without creating a data environment
Add text boxes to your form to display the desired fields from the primary table.
Set theof the text boxes to the primary table.
Add a grid to the form.
Set theof the grid to the name of the related table.
Set theof the grid to the name of the primary table.
Set theof the grid to the name of the index tag in the related table that corresponds to the relational expression of the primary table.
Set theof the grid to the expression that joins the related table to the primary table. For example, if the ChildOrder tag is indexed on
"lastname + firstname", set RelationalExpr to the same expression.
Either way you set up the one-to-many form, you can add navigation controls to move through the parent table and refresh the form objects. For example, the following code could be included in theof a command button:
SELECT orders && if orders is the parent table SKIP IF EOF( ) GO BOTTOM ENDIF THISFORM.Refresh
Comment or report problem with topic