ComponentOne DataObjects for .NET
Tutorial 4: Using C1ExpressView Component
DataObjects for .NET Express Edition > DataObjects for .NET Express Tutorials > Tutorial 4: Using C1ExpressView Component

In this tutorial, you will see how to use the C1ExpressView component to filter and sort table data and how to bind data-aware controls to table data that is defined in a different form. Complete the following steps:

  1. Add a command button to Form1 in the project built in Tutorial 3: C1ExpressConnection and Master-Detail Relations.
  2. Set the Text property of Button1 to Show Form2.
  3. Add the following code to the Button1_Click event:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim form As New Form2()
    form.ShowDialog()
    

    To write code in C#

    C#
    Copy Code
    Form2 form = new Form2();
    form.ShowDialog();
    
  4. Add a new form, Form2 to the project and place the following components on the form:
    Number of Components Name Namespace
    1 C1ExpressView C1ExpressView1 C1.Data.Express.C1ExpressView
    1 C1TrueDBGrid C1TrueDBGrid1 C1.Win.C1TrueDBGrid.C1TrueDBGrid
  5. Select the C1ExpressView1 component, and in the Properties window click the drop-down arrow next to the ExpressTableName property.
  6. Make sure that Form1 is open in the Visual Studio design time environment and select Form1.C1ExpressTable1. The ExpressTableName property shows the list of C1ExpressTable controls in the forms that are currently open.
  7. Enter the following values for C1ExpressView1 properties:
    Property Value
    RowFilter City = 'London'
    Sort ContactName
  8. Select the C1TrueDBGrid1 control and open the C1TrueDBGrid Tasks menu.
  9. Click the Choose Data Source drop-down arrow and select C1ExpressView1. This binds the grid to the C1ExpressView component.

Run the program and observe the following:

When you press the Show Form2 button, the form appears with the grid filled with filtered and sorted data from the Customers table: it includes only customers from London and is sorted by ContactName.


Notice that setting Sort is only one (programmatic) of the two possible ways to sort table data; the end user can also sort it interactively in the grid clicking on a column header.