ComponentOne True DBGrid for WinForms
True DBGrid for WinForms Tutorials / Tutorial 1: Binding True DBGrid to a DataSet
In This Topic
    Tutorial 1: Binding True DBGrid to a DataSet
    In This Topic

    In this tutorial, you will learn how to bind True DBGrid for WinForms controls to a DataSet and create a fully functional database browser. You will also learn about the basic properties of the True DBGrid for WinForms and then be able to run the program and observe the run-time features of the grid.

    Note: A video is available for this tutorial on the ComponentOne Videos Web page.

    Complete the following steps:

    1. Create a new .NET project.
    2. Open the Toolbox, which is initially located on the left side of the IDE and has a hammer and a wrench as its icon. From the Toolbox, locate and double-click the C1TrueDBGrid icon .
      The grid is added to the form and the C1TrueDBGrid Tasks menu appears.
    3. In the menu, select the Choose Data Source drop-down arrow and click Add Project Data Source.
    4. The Data Source Configuration Wizard appears and Database is selected. Click Next.
    5. Click the New Connection button to locate and connect to a database.
    6. Click the Browse button and locate the C1NWind.mdb file in the Documents\ComponentOne Samples\Common directory. Select it and click Open.
    7. 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.
    8. 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.
    9. In the next window, the Yes, save the connection as check box is checked by default and a name ("TDBGDemoConnectionString") has been automatically entered in the text box. Click Next to continue.
    10. In the Choose Your Database Objects window, select the tables and fields that you would like in your dataset.
             

      The DataSet is given a default name ("TDBGDemoDataSet") in the DataSet name text box.    

    11. Click Finish to exit the wizard. The DataSet, BindingSource and TableAdapter now appear on your form.
    12. Resize the grid and 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);
      
    13. Click the Design tab to return to the designer and then select the grid.
    14. Open the C1TrueDBGrid Tasks menu and select C1TrueDBGrid Tasks.
    15. Check the Enable Adding and Enable Deleting check boxes. This sets the AllowAddNew and AllowDelete properties of C1TrueDBGrid1 to True, enabling the user to add or delete records in the grid.

    Run the program and observe the following:

    Refer to Run-Time Interaction and try out the instructions for navigating, editing, and configuring the grid at run time.

    To end the program, close the window or press the stop button on the Visual Basic Toolbar.

    Congratulations, you have successfully completed binding True DBGrid to a DataSet!