ComponentOne List 8.0 for ActiveX
Tutorial 15 - Displaying Array Data in Unbound Application Mode

In this tutorial, you will learn how to use the unbound application mode (DataMode property set to 3 - Application) of True DBList to display an array of strings.  When the data source is an array, application mode is easier to use than either unbound mode (1) or unbound extended mode (2).  In application mode, the list fetches data one cell at a time, and you must program the UnboundGetRelativeBookmark event in order for the list to obtain the bookmark of a row.  For detailed instructions on how to use unbound mode 3, see Application Mode.

The TUTORIAL15.VBP project provides a complete sample that you can use as a template for implementing application mode.  This project is located in the TUTORIAL\TUTORIAL15 subdirectory of the True DBList installation directory.

  1. Start a new project.

  2. Place a True DBCombo control (TDBCombo1) on the form (Form1).

  3. Set the DataMode property of TDBCombo1 to 3 - Application (the default value of this property is 0 - Bound) and the MaxComboItems property to 14.

    Configuring the combo at design time

    We shall configure the combo as in Tutorial 14.

  4. Right-click TDBCombo1 to display its context menu.  Choose Properties to display the Property Pages dialog box.

  5. Select the Columns properties page by clicking the Columns tab. Set the Caption property of Columns(00) and Columns(01) to Column 0 and Column 1, respectively.

    Initializing the array data

    We first create and initialize a two-dimensional array to hold the data to be displayed in the list.  As in Tutorial 14, we will use a class module to encapsulate the unbound events.

  6. Add the CLASS1.CLS file from TUTOR15 directory to the project.  This class module will be responsible for storing data and responding to the combo's events.

    Displaying data in the unbound combo

    As explained in Tutorial 14, True DBList does not store your data in any of its unbound modes.  In unbound mode 3, whenever the list needs to display data in a cell, it will fire the ClassicRead event to ask for data from your data source.  Unlike unbound modes 1 and 2, the ClassicRead event does not use the RowBuffer object to transfer data several rows at a time.  Instead, the ClassicRead event fetches data one cell at a time.  When using application mode, you must also program the UnboundGetRelativeBookmark event in order for the list to obtain the bookmark of a row.

  7. Study the following implementation of the UnboundGetRelativeBookmark and ClassicRead events.  These events show how to provide bookmarks and data to the unbound combo.  Note that the code in the UnboundGetRelativeBookmark event is identical to the one used in Tutorial 13:

    Example Title
    Copy Code
    ' Fired when the Combo needs to reposition itself
    
    Private Sub TDBC_UnboundGetRelativeBookmark( _
    
        StartLocation As Variant, ByVal OffSet As Long, _
    
        NewLocation As Variant, ApproximatePosition As Long)
    
     
    
    ' TDBCombo1 calls this routine each time it needs to
    
    ' reposition itself.  StartLocation is a bookmark
    
    ' supplied by the list to indicate the "current"
    
    ' position -- the row we are moving from.  Offset is
    
    ' the number of rows we must move from StartLocation
    
    ' in order to arrive at the desired destination row.
    
    ' A positive offset means the desired record is after
    
    ' the StartLocation, and a negative offset means the
    
    ' desired record is before StartLocation.
    
     
    
    ' If StartLocation is NULL, then we are positioning
    
    ' from either BOF or EOF.  Once we determine the
    
    ' correct index for StartLocation, we will simply add
    
    ' the offset to get the correct destination row.
    
     
    
    ' If we are on a valid data row (that is, not at BOF or
    
    ' EOF), then set the ApproximatePosition (the ordinal
    
    ' row number) to improve scroll bar accuracy.
    
     
    
        Dim Index As Long
    
     
    
        If IsNull(StartLocation) Then
    
            If OffSet < 0 Then
    
                Index = MaxRow + OffSet
    
            Else
    
                Index = -1 + OffSet
    
            End If
    
        Else
    
            Index = Val(StartLocation) + OffSet
    
        End If
    
     
    
        If Index >= 0 And Index < MaxRow Then
    
           ApproximatePosition = Index
    
           NewLocation = Index
    
        Else
    
           NewLocation = Null
    
        End If
    
    End Sub
    
     
    
    ' Called when the Combo needs data
    
    Private Sub TDBC_ClassicRead(Bookmark As Variant, _
    
        ByVal Col As Integer, Value As Variant)
    
     
    
    ' When the list needs data in DataMode 3, it fires a
    
    ' ClassicRead event for each visible cell on the list
    
    ' to retrieve the data that will be shown there, so it
    
    ' fires on a cell-by-cell basis.  The cell that this event
    
    ' is firing for is specified by the Bookmark (which
    
    ' tells which row to fetch the data from) and the
    
    ' Col parameter (which gives the column index).
    
     
    
        Value = ComboArray(Col, Bookmark)
    
    End Sub
    
  8. In the General section of Form1, insert the following declarations:

    Example Title
    Copy Code
    Option Explicit
    
    Dim Sink As New Class1
    
  9. In the Form_Load (Visual Basic) event, initialize the elements of the Class1 instance and set the ApproxCount property of the combo accordingly.  The ApproxCount property is optional, but setting this value will enable the combo to position the vertical scroll bar accurately.

    Example Title
    Copy Code
    Private Sub Form_Load()
    
        Dim Row As Long, Col As Integer
    
     
    
        Row = 100
    
        Col = 2
    
     
    
        ' Initialize storage
    
        Sink.SetDims Row, Col
    
     
    
        ' Fill with values
    
        For Row = 0 To Sink.RowCount - 1
    
            For Col = 0 To Sink.ColCount - 1
    
                Sink.Value(Row, Col) = _
    
                    "Row " & Row & ", Col " & Col
    
            Next Col
    
        Next Row
    
     
    
        ' Initialize the class
    
        Sink.Attach TDBCombo1
    
     
    
        ' Calibrate the VScroll bar
    
        TDBCombo1.ApproxCount = Sink.RowCount
    
    End Sub
    

Run the program and observe the following:

To end the program, press the End button on the Visual Basic toolbar. You have successfully completed Tutorial 15.

 

 


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

Product Support Forum  |  Documentation Feedback