Skip to content

Loading cDBCJGrid Data

Automatically Loading cDbCJGrid Data

Data aware grids (cDbCJGrid) load their data automatically from the grid's data dictionary object structure (DDO structure).

The grid's Server property determines the main data dictionary object serving data to the grid. If this property is not set, then the parent container's Server property will be used.

The order of the grid rows is determined by the grid's Ordering property. This specifies which index to use of the Server DDO's main table. By default, this value is -1, which means that the most efficient index will be used according to how the data is constrained.

Each data aware grid column is bound to a table.column via the Entry_Item command. This information is used by the grid's data source (cDbCJGridDataSource) object to load data as needed.

Manually Loading cDbCJGrid Data

If you set pbStaticData to true and Auto_Fill_State to false, then you can load a customized set of static data using InitializeData.

This data can be edited just like any data aware grid, but it will not use the automatic finding services built into the cDbCJGridDataSource object.

This example shows how you would load data into a static cDbCJGrid:

Set pbStaticData to True
Set Auto_Fill_State to False

Procedure Activating
    Forward Send Activating
    Send LoadMyData
End_Procedure

Procedure LoadMyData
    Handle hoServer hoDataSource
    Boolean bFound
    tDataSourceRow[] DataSource
    Integer iRows iFile

    Get Server to hoServer
    Get Main_File of hoServer to iFile
    Send Request_Read of hoServer FIRST_RECORD iFile 1
    Move (Found) to bFound
    Get phoDataSource to hoDataSource

    While bFound
        If (Customer.State <> "CA") Begin
            // creates a datasourcerow based on current buffer data...
            Get CreateDataSourceRow of hoDataSource to DataSource[iRows]
            Increment iRows
        End
        Send Request_Read of hoServer GT iFile 1
        Move (Found) to bFound
    Loop

    Send InitializeData DataSource
    Send MovetoFirstRow
End_Procedure

The key instructions in this example are:

Get CreateDataSourceRow of hoDataSource to DataSource[iRows]

CreateDataSourceRow instructs the grid's datasource to populate a row data structure (tDataSourceRow). Each column in the grid is queried to determine the data binding. The row data structure is filled with the current values of the Table.Column buffer associated with each data binding. If a column does not have a data binding, then CreateDataSourceRow would call the column's OnSetCalculatedValue event to retrieve the row's value for that column. In addition, the appropriate table's row ID is stored in the row data structure, thus connecting the row to a specific record in the table.

In the example, we understand that the Customer table's global buffer needs to contain the record that we want to represent the grid row we are adding. This is done by finding each record in the table and creating the row data for each one we want to add to the grid.

Send InitializeData DataSource

Once we have populated our array of tDataSourceRow, we send InitializeData to initialize the grid's datasource with our data.

See Also