ComponentOne True DBGrid for WinForms
True DBGrid for WinForms Quick Start / Step 2 of 3: Binding True DBGrid for WinForms to a DataSet
In This Topic
    Step 2 of 3: Binding True DBGrid for WinForms to a DataSet
    In This Topic

    In this step, you'll learn how to bind a C1TrueDBGrid control to a DataSet. You will also learn about the basic True DBGrid properties and observe the run-time features of the grid. Complete the following steps to bind a C1TrueDBGrid control to a DataSet:

    1. Click C1TrueDBGrid1's smart tag to open the C1TrueDBGrid Tasks menu, select the Choose Data Source drop-down arrow, and click Add Project Data Source to add a new data source to your project.
    2. The Data Source Configuration Wizard appears and Database is selected. Click Next.
    3. Click the New Connection button to locate and connect to a database.
    4. Click the Browse button and locate C1NWind.mdb in the Documents\ComponentOne Samples\Common directory. Select it and click Open.
    5. Click the Test Connection button to make sure that you have successfully connected to the database or server and click OK. The new string appears in the data connection drop-down list.
    6. Click the Next button to continue. A dialog box will appear asking if you would like to add the data file to your project and modify the connection string. Click No.
    7. In the next window, the Yes, save the connection as check box is checked by default and a name has been automatically entered in the text box. Click Next to continue.
    8. In the Choose Your Database Objects window, you can select the tables and fields that you would like in your dataset. Select the Composer table.
      The DataSet is given a default name in the DataSet name text box.
          
    9. Click Finish to exit the wizard. The DataSet, BindingSource and TableAdapter now appear on your form.
    10. Double-click the form. Notice that Visual Studio has added the following code to the Form_Load event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.ComposerTableAdapter.Fill(Me.DsComposer.Composer)
      

      To write code in C#

      C#
      Copy Code
      this.composerTableAdapter.Fill(this.DsComposer.Composer);
      

    Run the program and observe the following:

    Notice that the data from the Composers table is reflected in the grid:


    True DBGrid retrieves the database schema information from the DataSet and automatically configures itself to display all of the fields contained in the database table. Note that the field names are used as the default column headings.

    Congratulations, you have successfully completed binding a C1TrueDBGrid control to a DataSet. In the next section you will customize the C1TrueDBGrid control's appearance and behavior settings.

    See Also