Binds the grid to an array of variants to be used as storage.
Syntax
[form!]VSFlexGrid.BindToArray [ VariantArray As Variant ], [ RowDim As Long ], [ ColDim As Long ], [ PageDim As Long ], [ CurrentPage As Long ]
Remarks
This method allows you to bind the VSFlexGrid control to a Visual Basic Variant Array or to another VSFlexGrid control.
When bound to an array, the grid displays values retrieved from the array and automatically writes any modifications back into the array. The array must have at least two dimensions and it must be an array of Variants. If the array has more than two dimensions, you may use the control to display one "page" of it at a time, and you may easily "flip pages".
The parameters on this method allow you to control how the rows and columns map onto the array's dimensions. By default, columns bind to the first array dimension (0) and rows bind to the second array dimension (1). This is the order used by ADO when returning recordsets with the GetRows method. The advantage of this default setting is that you may add or remove rows while preserving existing data using Visual Basic's Redim Preserve statement, which only allows the last dimension to be modified. If you don't like the default setting, you may define things differently.
The mapping is always from LBound to UBound on all dimensions. If you want to hide some rows or columns, set their height or width to zero. The binding does not apply to fixed rows or columns. It works only for the scrollable (data) part of the control.
If you change the contents or dimensions of the array, you should tell the control to repaint itself so the changes become visible to the user. You may do this with the Refresh method or by using the BindToArray method again.
To unbind the control, call the BindToArray method with a Null parameter:
fg.BindToArray Null
The example below illustrates several variations on this theme. The demo project included in the distribution package has more examples.
' ** Two-dimensional binding:
Dim arr(4, 8)
' Default binding:
fg.BindToArray arr
' fg now has 5 non-fixed columns (0-4) and 9 non-fixed rows (0-8).
' the mapping is: arr(i, j) = fg.TextArray(j - fg.FixedRows, i - fg.FixedCols)
' Transposed binding:
fg.BindToArray arr, 0, 1
' fg now has 9 non-fixed columns (0-8) and 5 non-fixed rows (0-4).
' the mapping is: arr(i, j) = fg.TextArray(i - fg.FixedRows, j - fg.FixedCols)
' ** Three-dimensional binding (AKA cube, notebook):
ReDim arr(4, 8, 12)
' Default binding:
fg.BindToArray arr
' by default, the last dimension becomes the "pages", and the
' current page is the first (0), so
' fa now has 5 non-fixed columns (0-4) and 9 non-fixed rows (0-8).
' the mapping is: arr(i, j, 0) = fg.TextArray(j - fg.FixedRows, i - fg.FixedCols)
' Page Flipping:
fg.BindToArray arr, , , , 2
' the row, col, and page settings are the default, and the current
' page is 2 (instead of the default 0), so
' fg now has 5 non-fixed columns (0-4) and 9 non-fixed rows (0-8).
' the mapping is: arr(i, j, 2) = fg.TextArray(j - fg.FixedRows, i - fg.FixedCols)
The BindToArray method also allows you to bind the control to another VSFlexGrid control. This way, you may create different "views" of the same data without having to keep duplicate copies of the data. The syntax is the same:
fg.BindToArray fgSource
In this case, the fg control will display the data stored in the fgSource control. Changes to cells in either control will reflect on the other. When binding to another VSFlexGrid control, the fixed cells are bound as well as the scrollable ones. The binding only applies to the data, not to the cell formats.
To load data from an array or another VSFlexGrid control without binding, use the LoadArray method instead.