Visual Basic Concepts
Before you can use its features, you must bind data to the Hierarchical FlexGrid. You can bind data to this control either at design time using the Properties sheet, or programmatically at run time.
Once your Hierarchical FlexGrid is bound to a data source, the design-time display within the Hierarchical FlexGrid is a single blank column and single blank row. The field and band information is not automatically retrieved (to obtain this information, see Retrieving Structure). If the Hierarchical FlexGrid is run without field and band information, the data displays using the default property settings. That is, if the Hierarchical FlexGrid is bound to a hierarchical Command, the bands of data display horizontally with each band containing a column for each field in the Recordset.
Hierarchical FlexGrid bound to the Data Source
This section describes how to bind the Hierarchical FlexGrid to a data source at design time.
To bind the Hierarchical FlexGrid at design time
The data source can be a DataEnvironment object or an ActiveX® Data Object (ADO) Data Control, a new Visual Basic feature. For this procedure, create the data source as a DataEnvironment object.
-or-
On the Visual Basic toolbox, double-click the MSHFlexGrid control to drop it on a Visual Basic form.
Caution If the DataSource is reset, any user-defined modified data in the Hierarchical FlexGrid cells is lost.
-or-
Press F5.
This section describes how to bind data to the Hierarchical FlexGrid programmatically.
To set the DataSource programmatically
Note To set the data source programmatically, the project must have a reference to Microsoft ActiveX Data Objects: On the Project menu, choose Select References, and then select Microsoft ActiveX Data Objects 2.0 Library.
<myDataSource>
with the actual name of your data source):
DIM Cn As New Connection, Rs As New Recordset
' You need to replace <myDataSource> with a valid
' DSN on your system.
Cn.ConnectionString = "DSN=<myDataSource>"
' Use the following code for SHAPE Commands
Cn.Provider = "MSDataShape"
Cn.CursorLocation = adUseNone
' Alternatively, for SQL Commands, use the following code
Cn.CursorLocation = adUseNone
Cn.Open
' You need to specify a valid data source for
' your Recordset for the Connection created above
Rs.Source = "<valid SQL SELECT command>"
' Now associate the Command with the Connection
' and execute them.
Set Rs.ActiveConnection = Cn
Rs.Open
Set MSHFlexGrid1.DataSource = Rs
-or-
Press F5.