ComponentOne True DBGrid Pro 8
Tutorial 19 - Displaying Array Data in Unbound Storage Mode

In this tutorial, you will learn how to use the unbound storage mode (DataMode property set to 4 - Storage) of True DBGrid to display an array of strings. Unlike unbound (extended) and application modes, storage mode does not fire data-gathering events. Instead, it uses an XArrayDB ActiveX object to store, access, and maintain data.

In code, you create, redimension, and populate an XArrayDB object with your data just as you would a Visual Basic array, then assign the XArrayDB object to the Array property of the grid. The data will then be maintained and exchanged between the grid and the XArrayDB object automatically. There are no unbound events to write, making this mode the easiest to use.

  1. Start a new project.

  2. Place a True DBGrid control (TDBGrid1) on the form (Form1).

  3. Set the DataMode property of TDBGrid1 to 4 - Storage (the default value of this property is 0 - Bound).

    Configuring the grid at design time

    We shall configure the grid to display four columns.

  4. Right-click TDBGrid1 to display its context menu and choose Edit from the context menu. The grid will enter its visual editing mode, enabling you to interactively change the grid's row and column layout.

  5. By default, the grid contains two columns. We are going to create two more. Right-click anywhere in the grid to display the visual editing menu. Choose the Append command to add a new column at the end of the grid. Execute this command again to get a total of four columns.

  6. Right-click TDBGrid1 to display its context menu.

  7. Choose Properties to display the Property Pages dialog. On the General property page, set the AllowAddNew and AllowDelete properties to True. (Note that the AllowUpdate property is True by default.)

  8. Click the Columns tab to display a list of the available columns, designated as Columns(00) through Columns(03). Expand the Columns(00) node and set its Caption property to "Column 0". Repeat the process for the remaining columns until the grid looks like this.

    Adding XArrayDB to the project

    Before writing the code, we need to add the ComponentOne XArrayDB Object to the project.

  9. Select References from the Project menu to display a list of available type library references. Select the check box labeled ComponentOne XArrayDB Object (XADB8.OCX), then press the OK button.

    Initializing the array data

    Next, create the XArrayDB object in code.

  10. In the General section of Form1, insert the following declarations:

    Example Title
    Copy Code
    ' General declarations.
    
    Option Explicit
    
     
    
    Dim x As New XArrayDB
    
  11. In the Form_Load event, ReDim the XArrayDB object to contain 100 rows and 4 columns. After populating the XArrayDB object, assign it to the grid's Array property.

    Example Title
    Copy Code
    Private Sub Form_Load()
    
        ' Allocate space for 100 rows, 4 columns.
    
        x.ReDim 0, 99, 0, 3
    
     
    
        Dim row As Long, col As Integer
    
     
    
        ' The LowerBound and UpperBound properties correspond to the LBound and
    
        ' UBound functions in Visual Basic. Hard-coded dimensions can be used
    
        ' instead, if known.
    
        For row = x.LowerBound(1) To x.UpperBound(1)
    
            For col = x.LowerBound(2) To x.UpperBound(2)
    
                x(row, col) = "Row " & row & ", Col " & col
    
            Next col
    
        Next row
    
     
    
        ' Bind True DBGrid Control to this XArrayDB instance.
    
        Set TDBGrid1.Array = x
    
    End Sub
    

Run the program and observe the following:

This concludes Tutorial 19.

 

 


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

Product Support Forum  |  Documentation Feedback