Tutorials - True DataControl > Tutorial 6 - A Common Example of a Master-Detail Relationship |
The True DataControl model of the master-detail relationship is extremely extensive and flexible. It can be used to implement a variety of situations in application development that would otherwise need manual coding. Its diversity is, in fact, the focus of Tutorials 5, 6, 7, 8, 9, 13, and 14. The example by which it was introduced in the previous tutorial might not be recognized as a common case of what is usually called a "master-detail" or "one-to-many" relationship. This tutorial will furnish a more common example where the position in one data set determines data contained by another. In this example, three TData controls are connected to form a three-level master-detail chain.
Start a new project.
Place the following controls on the form (Form1) as shown in the figure: three TData controls (TData1 to 3) and three DataGrid controls (DataGrid1 to 3).
Set properties as follows (you can use the DataSource property page to set TData data source properties, as described in Tutorial 3):
Example Title |
Copy Code
|
---|---|
TData1.ConnectionString Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Program Files\ComponentOne Studio\Common\TDDEMO.MDB TData1.CommandType 2 – adCmdTable TData1.RecordSource Customers DataGrid1.DataSource TData1 TData2.ConnectionString Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Program Files\ComponentOne Studio\Common\TDDEMO.MDB TData2.CommandType 2 – adCmdTable TData2.RecordSource Orders DataGrid2.DataSource TData2 TData3.ConnectionString Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Program Files\ComponentOne Studio\Common\TDDEMO.MDB TData3.CommandType 2 – adCmdTable TData3.RecordSource [Order Details] DataGrid3.DataSource TData3 |
Open the True DataControl property pages for TData2. On the General page select TData1 in the Master combo box. On the True DataControl property pages for TData3, in the General page, select TData2 in the Master combo box.
On the Fields page for TData2, select the CustomerID field. Click the right mouse button over the CustomerID field and select New Range Condition from the menu (alternatively, you can use the New button). An empty range condition for the CustomerID field appears with controls for entering the condition now visible in the right part of the page. Go to the Value Expression text box and type the following expression: TData1.CustomerID. This will create a CustomerID = TData1.CustomerID range condition for the CustomerID field.
Now go to the TData3 property pages and create a range condition OrderID = TData2.OrderID for the OrderID field, following the same procedure as in the previous step.
When you select an order record in DataGrid2, the contents of DataGrid3 changes to the set of Order Details records that correspond to the selected OrderID. When you select a customer record in DataGrid1, the contents of both DataGrid2 and DataGrid3 changes. DataGrid2 shows all orders placed by the selected customer, and DataGrid3 shows order details of the first order that became current in DataGrid2.
This is all accomplished without requiring a single line of Visual Basic code. As a matter of fact, you have not written one single line of code since you started with Tutorial 1! This is how to get the most out of True DataControl: write as little code as possible, so that your applications will be easy to create and maintain.
Close the program. You have successfully completed Tutorial 6.