ComponentOne True DataControl 8.0
Tutorial 1 - Using TDataLite with Bound Controls: ComponentOne TDBGrid and Other Controls

In this tutorial, you will learn how to use TDataLite with ComponentOne True DBGrid (TDBGrid) and other controls. ComponentOne TDBGrid and TDataLite controls are closely integrated, so your grids can take full advantage of the data management features supplied by TDataLite. But you can use TDataLite with other controls as well.

This tutorial consists of two projects: in DataGrid and TDBGrid subdirectories. The DataGrid project shows how to use TDataLite with controls other than TDBGrid, such as Microsoft DataGrid. The TDBGrid subdirectory shows the interaction between TDataLite and ComponentOne TDBGrid control. We’ll start with DataGrid:

  1. Start a new project.

  2. Place the following controls on the form (Form1) as shown in the figure: a TDataLite control (TDataLite1), an ADODC control (Adodc1) and a DataGrid control (DataGrid1).

  3. Set 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        Customers
    
    TDataLite1.DataSource      Adodc1
    
  4. Select TDataLite1, and click the right mouse button over it to open the control's context menu. Select the TDataLite Properties option. This will open the property pages dialog, where you can view and edit the properties of TDataLite1. The dialog looks like this:

    In the General property page check all the check boxes in the Buttons group. Close the property pages by clicking the OK button or by pressing Enter. This will save the changes you have just made for TDataLite1. You will see thirteen buttons appear on the TDataLite1 control.

  5. Set the DataSource property of DataGrid1 to TDataLite1. This binds the DataGrid1 control to the TData1 control. TDataLite1 becomes the data source for the grid. Set the grid’s AllowAddNew and AllowDelete properties to True.

    Run the Program and Observe the Following:

    • DataGrid1 displays data from the Customers table.

    • TData1 has thirteen buttons on it, providing useful functions that you otherwise would have had to implement with tedious manual coding. These include data management functions, such as AddNew, Delete, Update, Cancel, and two standard dialogs: Find and Bookmarks. All buttons have tooltips, so you can easily identify them. Try the Find and Bookmarks buttons. The Find dialog is easy to use and self-explanatory. To use the Bookmarks dialog, press the Bookmarks button, enter a bookmark name and press Add. Repeat this on different data rows. You will see several bookmarks listed in the Bookmarks dialog. You can jump to any of these bookmarks pressing the Go To button.

    • Try the True DataControl query mode. This is a powerful feature that adds a lot to your application without requiring a single line of code. Press the Query button on the TDataLite control. This will switch it to query mode: DataGrid1 becomes empty and contains one data row. Add another row to DataGrid1 and enter the following data in the two rows: CompanyName = B's Beverages in the first row and City = Rio de Janeiro in the second row. Press the Query button again to leave query mode. You will see that the query is applied and its result, four rows of data, appears in DataGrid1. Go back to query mode by pressing the Query button, and delete the first row (CompanyName = B's Beverages) from the grid. Apply the query pressing the Query button again; you will see that the result has changed accordingly. Returning to query mode, enter Hanari Carnes in the CompanyName field in the same row. Switch to the result mode, and you will see that now there is only one row satisfying the query. In formal querying terms, the query conditions are connected with the logical operator AND when they belong to the same row in query mode. Different rows in query mode are connected with OR.

  6. Close the program. Back in design mode, set the DataSource property of DataGrid1 to Adodc1. This binds the DataGrid1 control to Adodc1 as its data source, so DataGrid1 is no longer directly bound to TDataLite1. Still, you can use TDataLite1 buttons to navigate the recordset and perform the actions implemented by TDataLite. As you will see in other tutorials, most of TDataLite features, such as constraints, default values, etc, are still available in this mode. This is because TDataLite1 is bound to the same DataSource as DataGrid1. However, not all TdataLite features are available in this mode. For example, if you press the Query button, you will see that nothing happens. In order to be able to use query mode, you must bind DataGrid1 to TDataLite1 directly. This binding does not actually change anything, DataGrid still uses Adodc1 as its data source, even if it is bound to TDataLite1. But binding directly to TDataLite enables query mode and also allows you to use memory array data (DataMode = 1 – tdbModeMemoryArray, see Tutorial 3).

    Now we will look at the other project of this tutorial, the one in the TDBGrid subdirectory.

  7. Repeat steps 1 – 5, but this time use ComponentOne True DBGrid 8.0 (TDBGrid) instead of Microsoft DataGrid control.

  8. Open TDataLite1 property pages by select the TDataLite Properties option in TdataLite1 context menu. Select the Fields property page. You will see all fields of the Customers table. In this example, we need to expose three fields: CustomerID, CompanyName, and City. To do this, one at a time select each of the other fields in the data source tree-view window, and clear the Visible check box for all of them. An empty check box means that the field is accessible to your TDataLite control, but is not exposed to controls that are bound to it.

  9. To change the field order from that of the database table, drag and drop the field names. For example, press the left mouse button over the City field name. Without releasing the button, move your mouse to the CompanyName field position, then release the button. The City field is now visibly positioned before the CompanyName field.

  10. Close the property pages by clicking the OK button or by pressing Enter. This will save the changes you have just made for TDataLite1.

Run the Program and Observe the Following:

TDBGrid1 displays data from the Customers table: CustomerID, City, and CustomerName. There is one column for each field marked as Visible in the property pages.

If you will return to the DataGrid project and try to do the same, you will see that DataGrid1 still displays all the fields of the Customers table, not the three fields you defined in TDataLite1. The real data source for DataGrid1 is still Adodc1, not TDataLite. Although TDataLite1 appears as the value of DataGrid1.DataSource, TDataLite1 simply delegates to its DataSource, to Adodc1, so DataGrid1 displays the data as it is supplied by Adodc1. This is because DataGrid is not a ComponentOne control, so it does not have the intimate knowledge of TDataLite that TDBGrid has. Although you can use controls other than TDBGrid with TDataLite, in order to benefit fully from all TDataLite features, you must use TDBGrid, or purchase the full version – True DataControl.

Congratulations, you have successfully completed Tutorial 1!

 

 


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

Product Support Forum  |  Documentation Feedback