Storage Mode > Using the XArrayDB Object > Attaching an XArrayDB object to a True DBGrid control |
Since XArrayDB objects can only exist at run time, you must write code to associate them with a TDBGrid or TDBDropDown control. This is done by setting the Array property:
TDBGrid1.Array = MyArray
Once this association is made, the grid will store a reference to the XArrayDB object and query it as needed to determine the contents of individual cells. When the Array property is set, the grid also determines the number of rows (the first dimension) in an XArrayDB object and calibrates the vertical scroll bar accordingly.
However, the grid will never adjust its column layout to match the number of columns (the second dimension) in an XArrayDB object. As with other unbound data modes, you must define the column layout yourself at design time, run time, or a combination of both. At run time, you can use the following code to clear the existing columns from a grid, then create a new one for each XArrayDB column:
Example Title |
Copy Code
|
---|---|
Dim C As TrueDBGrid80.Column With TDBGrid1.Columns While .Count > 0 .Remove 0 Wend While .Count < MyArray.Count(2) Set C = .Add(0) C.Visible = True Wend End With |
Note that newly created columns are invisible by default, so you must explicitly set their Visible property to True.