ComponentOne Input for WinForms
Binding to a C1DataExpress Data Source
Input for WinForms Tutorials > Binding C1Input Controls to a Data Source > Binding to a C1DataExpress Data Source

To bind to a C1DataExpress data source, complete the following steps:

  1. Create a new Windows Application project.

  2. Place the following components on the form as shown in the figure:
    • C1ExpressTable1 (C1.Data.Express.C1ExpressTable)
    • C1Label1-2 (C1.Win.C1Input.C1Label)
    • C1PictureBox1 (C1.Win.C1Input.C1PictureBox)
    • C1TextBox1 (C1.Win.C1Input.C1TextBox)
    • C1DbNavigator1 (C1.Win.C1Input.C1DbNavigator)

  3. Select the C1ExpressTable1 component, go to the Properties window, select the ConnectionString property drop-down arrow and select New Connection.

    The Add Connection dialog box opens.

  4. Select the provider, the database, and other necessary connection properties in that dialog box.

    In these tutorials, we use the standard MS Access Northwind sample database (C1NWind.mdb). Add the following to the ConnectionString property: Provider=Microsoft.Jet.OLEDB.4.0;Data Source="Documents\ComponentOne Samples\Common\C1NWind.mdb".

  5. For the C1ExpressTable1 component, open the DbTableName property box and select Employees from the Database Table list.

    Now, we will bind some C1Input controls to the data control. Suppose we want to show the first name, date of birth, notes, and photo for each employee. The first name and date of birth will be displayed in C1Label controls, notes in C1TextBox, and photo in C1PictureBox.

  6. For the C1Label1 control, go to the Properties window, select C1ExpressTable1 from the drop-down list for the DataSource property.
  7. Then select FirstName from the list for the DataField property.
  8. Bind the C1Label2 DataSource property to C1ExpressTable1 and the C1Label2 DataField property to BirthDate and C1TextBox1 DataSource property to C1ExpressTable1 and the C1TextBox1 DataField property to Notes.
  9. After binding the C1Label2 control, you can notice that its DataType property is set to the field type, DateTime. Now, change the format for C1Label2 so that it will not show time with the date of birth (showing time is the default). To change the format, select the FormatType property, open its combo box and select MediumDate.

    Next, bind the C1PictureBox control to the Photo field.

  10. First select C1ExpressTable in the DataSource property combo box of the C1PictureBox control.
  11. Open the DataField property combo box and select Photo from the list of available fields.
  12. Set up the C1DbNavigator1 control allowing the user to navigate through the data set. To bind the navigator control to the data source, select C1ExpressTable1 in its DataSource property combo box.
  13. To dock the navigator control to the bottom of the form and separate it from the rest of the form with a three-dimensional line, set the following properties:
    • C1DbNavigator1.Dock = Bottom
    • C1DbNavigator1.BorderStyle = Fixed3D

Run the program and observe the following:

C1Input controls show data in Employees records. You can navigate between Employees records using the four VCR-style buttons of the navigator control. You can also go directly to a certain record by typing the record number in the navigator control record number edit field, or set the input focus to the record number field and use mouse wheel to scroll through the records.