ComponentOne True DataControl 8.0
Tutorial 6 - Using Filter Conditions and Parameters in TDataLite

This tutorial describes how to restrict the recordset by imposing a filter condition. You will also learn how to use TDataLite parameters.

Note: Filter conditions are only accessible to TDBGrid 8.0 bound to TDataLite. If you need to use filters with other controls, use the full version -True DataControl. See the ComponentOne Web site for details.
  1. Start a new project.

  2. Place the following controls on the form (Form1) as shown in the figure: an ADODC control (Adodc1), a TDataLite control (TDataLite1), a True DBGrid 8.0 control (TDBGrid1), a TextBox control (Text1), a label (Label1) and a button (Command1).


  3. Set the properties as follows:

    Example Title
    Copy Code
    Adodc1.ConnectionString
    
    Provider=Microsoft.Jet.OLEDB.3.51;Persist Security
    
    Info=False;Data Source= C:\Program Files\ComponentOne Studio\Common\TDBGDemo.mdb
    
    Adodc1.CommandType   2 – adCmdTable
    
    Adodc1.RecordSource  Orders
    
    TDataLite1.DataSource      Adodc1
    
    TDBGrid1.DataSource  TDataLite1
    
  4. For this tutorial, we will need to define a parameter in the TDataLite control. Like fields, parameters are TDataLite variables, they can be used in True DataControl expressions. You can access parameter values at run time through the Parameters collection, see Step 7 below. Parameters differ from fields in that their values don’t depend on a particular record the TDataLite is positioned on. To create a parameter, select the Parameters property page for TDataLite1. Note that the parameter list on the left is initially empty. Click the right mouse button over the parameter list and select New from the menu (alternatively, you can press the New button). A new parameter with the default name PARAM_0 will appear. Change the name to Interval by typing it into the Name text box. Select Integer in the Data Type combo box. You have now created an Interval parameter.

  5. Go to the Filters property page of TDataLite1. Create a new filter by right-clicking the filter list on the left side of the page and choosing New from the context menu (alternatively, you can use the New button). This enables the expression editing controls on the right side of the page. Type the following text into the Filter Expression box:

    Example Title
    Copy Code
    RequiredDate - ShippedDate  > Interval
    

    Type the following text into the Condition box:

    Example Title
    Copy Code
    Not IsNull(Interval)
    

    As described in previous tutorials, you can also use the Expression Editor to build the expression.

    You have created a filter condition that reads as:

    Example Title
    Copy Code
    (if (Not IsNull(Interval)) RequiredDate - ShippedDate > Interval
    

    This means that:

    • The condition will be applied only if the Interval parameter is not empty.

    • In this case, TDataLite1 will only include records where RequiredDate - ShippedDate > Interval.

    More than one filter condition may be imposed. Usually, each filter is accompanied by a condition specifying its applicability, as in this example.

  6. Go to the General property page and check the Filtered check box.

    IMPORTANT!          If you omit this step, all filters will be ignored!

  7. Add the following code to Command1:

    Example Title
    Copy Code
    Private Sub Command1_Click()
    
        TDataLite1.Parameters("Interval") = Text1.Text
    
    End Sub
    

Run the Program and Observe the Following:

Close the program. You have successfully completed Tutorial 6.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback