Setup a Master Detail Relationship

This exercise describes how to add DataGrids to define a Master-Detail relationship between two tables:

Master

  1. Click and drag a DataGrid from the Toolbox to the Design Sheet. This will be bound to the Master (Parent) dataset:
  2. To bind the DataGrid to the rows and columns of the Master dataset, select Set Data Binding from the control drop-down menu:
  3. Choose the Master dataset to bind to the DataGrid:

    The binding is shown on the DataGrid:

    (If the dataset binding string is truncated on smaller controls, to see the full string you can hover the mouse over the binding icon.)

Detail

  1. Click and drag a second DataGrid from the Toolbox to the Design Sheet. This will be mapped to the Detail (Child) dataset:
  2. To bind the DataGrid to the rows and columns of a Detail dataset, select Set Data Binding from the control drop-down menu:
  3. Choose the dataset to bind to the DataGrid:

    The binding is shown on the DataGrid:

    Note:

    • You can click and drag the corners of the grid to resize it.
    • By default, Best Fit is applied to the widths of the columns in the grid. Note that, while the row height may be temporarily adjusted, the row height will return to the default setting when the form is closed and subsequently re-opened.
    • The columns in the grid are re-sizable by clicking and dragging on the left or right-hand border of a column in the column header.
    • To apply a "Best fit" for a column after it has been re-sized, in the column header, double click on the right-hand border of the column.
    • The order of the columns in the grid can be changed by clicking in the column header of a column and dragging to the left or right.
    • To sort by a particular column, click in the header of that column to toggle ascending and descending order.
    • To sort by multiple columns, use SHIFT + click to add a second, third, and subsequent columns to sort by.
  4. Add NavigationBars for the DataGrids. See: Navigate a Dataset
  5. Save your changes and click Run to run the form:

When you navigate the Master (Project) DataGrid, the Project is updated in the Detail (Collars) DataGrid.

Note that the Master-Detail relationship is based on the “Master dataset” setting of the Detail dataset. In this example, Project has already been configured as the Master dataset of the Collar dataset. Synchronisation between the bound DataGrids therefore works automatically.