| DataObjects for .NET Express Edition > C1ExpressConnection: Combining Tables into Data Sets > Master-Detail Relations |
When master-detail relations are defined between tables in a C1ExpressConnection component, they can be used to build data-bound master-detail forms and to navigate parent/child rows programmatically (with GetChildRow(s)/GetParentRow(s) methods). To create a master-detail relation, check the Master-detail check box in Relations editor.
Having a master-detail relation, you can bind two data-aware controls, one to the master and the other to the detail, and the detail control will follow the master, will be automatically populated with child rows of the parent row on which the master is currently positioned. In presence of master-detail relations, the DataMember combo box of a data-aware control shows tables participating in the master-detail hierarchy preceding with underscore, whereas the same tables regarded as standalone (not restricted by master-detail relations) are shown without underscore. For example, if you have a "Customers – Orders" relation, this is how you can bind a master and a detail grid:
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
ParentGrid1.DataMember = "_Customers" ParentGrid1.DataSource = C1ExpressConnection1 ChildGrid1.DataMember = "_Customers.Customers-Orders" ChildGrid1.DataSource = C1ExpressConnection1 |
|
To write code in C#
| C# |
Copy Code
|
|---|---|
parentGrid1.DataMember = "_Customers"; parentGrid1.DataSource = C1ExpressConnection1; childGrid1.DataMember = "_Customers.Customers-Orders"; childGrid1.DataSource = C1ExpressConnection1; |
|
![]() |
Tip: If you want to add related rows to the master and detail tables at once in a C1ExpressConnection, use a connection type other than OleDb. For native SQL Server connectivity select SQLServer for the connection type. For native Oracle access use either Oracle or MSOracle connection type. |