ComponentOne True DBGrid for WinForms
True DBGrid for WinForms Tutorials / Tutorial 3: Linking Multiple True DBGrid Controls
In This Topic
    Tutorial 3: Linking Multiple True DBGrid Controls
    In This Topic

    This tutorial demonstrates how to link multiple True DBGrid for WinForms controls using a Master Detail dataset.

    Complete the following steps:

    1. Create a new .NET project.
    2. Navigate to the Visual Studio Toolbox and double-click the C1TrueDBGrid item twice to add two C1TrueDBGrid controls to the form (C1TrueDBGrid1 and C1TrueDBGrid2).
    3. In the C1TrueDBGrid1 control's C1TrueDBGrid Tasks menu, locate the Choose Data Source drop-down and select Add Project Data Source.
    4. In the adapter's Data Source Configuration Wizard, either select a connection to C1NWind.mdb or create a new connection to this database. On the Choose your database objects page of the wizard, select all fields in the Composer table and all fields in the Opus table, and type "DsMasterDetail" into the DataSet name box, and then finish out the wizard.
    5. Double-click DsMasterDetail.xsd in the Solution Explorer window. This will open the DsMasterDetail.xds file, which will appear similar to the following:
    6. To make a relation between two tables, click and hold down the mouse button in the area next to the Last field in Composer, and then drag the mouse up over the Composers table over to the Opus table, then release the mouse over the area next to the Last field. This will bring up the Relation dialog box:

      Make sure Parent Table is set to Composer and the Child Table is set to Opus. In addition make sure both fields are set to the Last column and that the Relation Only is selected (as in the preceding screenshot). Click OK and exit the Edit Relation dialog box.
    7. Now go to the Build menu of Visual Studio and choose Build Solution. This will ensure that this new relation is available in the project.
    8. Return to the form's Design view and in the Toolbox, locate the <Your Project Name> Components tab. Add an instance of the DsMasterDetail, ComposerTable, and OpusTableAdapter to the form.
    9. Now in the Properties window, set the DataSource property for the first C1TrueDBGrid control to DsMasterDetail1 and the DataMember property to Composer.

      If prompted to replace the column layout, click Yes.
    10. For the second C1TrueDBGrid control, set the DataSource property to DsMasterDetail1 and the DataMember property to Composer.Composer_Opus.

      If prompted to replace the column layout, click Yes.
    11. All that is left is to populate the DataAdapters.
    12. Double-click the form to switch to Code view and create the Form_Load event handler. Add the following code to the Load event of Form1:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.ComposerTableAdapter1.Fill(Me.DsMasterDetail1.Composer)
      Me.OpusTableAdapter1.Fill(Me.DsMasterDetail1.Opus)
      

      To write code in C#

      C#
      Copy Code
      this.composerTableAdapter1.Fill(this.dsMasterDetail1.Composer);
      this.opusTableAdapter1.Fill(this.dsMasterDetail1.Opus);
      

    Run the program and observe the following:

    This concludes this tutorial; you've successfully completed linking multiple True DBGrid controls.