Before you can use its features, you must bind data to the Hierarchical FlexGrid. You can bind data to this control either using Visual Basic's new Data Binding Manager or programmatically.
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 use the Visual Basic Data Binding Manager to bind data to your Hierarchical FlexGrid. This Data Binding Manager provides a user interface that promotes ease-of-use when binding data.
To set the DataSource using the Visual Basic Data Binding Manager
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.