In this lesson, you will learn how to create a form to display records related to the current record within a grid.
A form created in the previous lesson shows one record from the “customer” table at a time. In this lesson, you will display the payments of the customer using the TableView control.
There are three ways to define how the TableView control can find the related records:
All three of these methods are covered in this tutorial.
Open an existing local project.
In this part, we will use an existing database link (foreign key) between two tables to find the set of related records.
To show the related records a TableView control will be used.
As you can see the Link property now contains the name of the used link:
The grid displays the records related to the current record of the form.
The map of fields defines the correspondence between fields of the form and fields of the TableView control. Only those records are shown in the TableView for which the values of the mapped fields match.
The map of fields is useful if there are no links in the database or if the records source is a view or a query.
The map of fields will be used instead of the link, so it is necessary to clear the Link property.
A new value for the map now is shown in the Property Inspector:
The grid displays the records related to the current record of the form, just like in the previous part.
The map of parameters can be used when the source of the TableView is a query with parameters. This way is more flexible than the previous because allows the user to define an exact query that will be executed.
Such query contains the special parameter placeholder, $p(param_name), which is replaced with the actual values during the form execution.
The map of parameters defines the correspondence between the parameter and the field in the form.
At first we must create a query which will be the source for the TableView.
The query is completed with the parameter now:
SELECT * FROM payment WHERE customer_id = $P(pCustomerId)
You can see a new query on the project tab
Now the map of parameters is defined:
The grid displays the records related to the current record of the form, just like in the previous parts.
Not sure you did it right? You can find a completed version of the project from this lesson here.