ComponentOne True DBGrid Pro 8
Hierarchical Data Display

The OLE DB version of True DBGrid now supports the ability to display hierarchical data. Hierarchical data generally refers to data that is stored in multiple relational tables, where a master (or "parent") table is linked by keyed fields to detail (or "child") tables. The hierarchical display gives you the ability to present the master data to your users, such that the related detail data can be viewed in the same grid with a single mouse click.

When the grid is bound to a master-detail data source, you can display related groups of hierarchical data by using bands. A band is a virtual representation of a hierarchical recordset, not the data itself. A band is created for each level in a hierarchical recordset, and may consist of entire tables or a just a few selected fields. At run time, users can expand and collapse bands using a TreeView-like interface.

To use this feature, the DataMode property must be set to 0 – Bound, and the DataView property must be set to 1 – Hierarchical. The grid control must be bound to a hierarchical recordset. One way to do this is to use the DataSource property and/or the DataMember property (if you are binding to a Data Environment created with the Visual Basic Data View window). Another way is to create an ODBC Data Source, as described in Tutorial 24.

The following example illustrates the hierarchical relationships in a master-detail data source named DataEnvironment1. There are three recordsets, or Bands in this example. Customers is the master band (Band 0), whose fields will be displayed in the grid first. Relationships between Customers and Orders (Band 1), and between Orders and Order_Details (Band 2) enable you to create a nested display of detailed data for your users to expand and collapse as needed. Each Customers record is joined to the Orders records by a relation defined on the CustomerID fields. Orders are joined to the Order_Detail data by a relation defined on the OrderID fields.

Note that the Customers and Orders recordsets contain more fields than the ones shown; an SQL statement was used to select the fields of interest.

At run time, the grid displays read-only data. The next figure illustrates the initial display of DataEnvironment1. The data from the master recordset (Customers) is displayed first, and the fields from the detail recordset bands appear to the right. The detail recordset fields initially contain no data, however. An expand icon ("+") at the left edge of a record indicates the presence of hierarchical data. Note that in this example, only one record, CustomerID FISSA, has no detail records.

When the user clicks an expand icon, it changes to a collapse icon ("–") and the next band (Orders) expands to show the detail records for the clicked row. Note that the CustomerID field of the Orders table also contains expand icons, which indicate the presence of an additional hierarchical level as shown in the next figure. Users can expand each Orders record to display the detailed order information held in Order_Details. The grid can therefore display detailed order information for each customer in a single view.

In this example, if a user clicks the collapse icon in the CustomerID field (CONSH), the records held in the Order_Details fields collapse (OrderID, ProductID, and so on), and are no longer visible. Also, the collapse icon changes back to an expand icon. However, if the user clicks the collapse icon in the ContactName field (Elizabeth Brown) first, the fields in the Order as well as the Order_Details band collapse, and the grid will look the same as it did when it was first displayed.

Note: If the DataView property is set to its default value of 0 – Normal, the grid will only display flat files; it will not support a hierarchical view. Even if the data source is a hierarchical recordset, the grid will only display data from the master table. It will be necessary to distribute xadb8.ocx if you are setting the True DBGrid’s DataView property to hierarchical.

The DataView property must be set at design time; you cannot change it at run time.

The following methods are provided for manipulating hierarchical grid displays:

GetBand

Returns the band for a specified column index

CollapseBand

Collapses all rows for the specified band

ExpandBand

Expands all rows for the specified band

RowExpanded

Returns True if the current row is expanded within the specified band

If the number of recordset levels in a master-detail data source is not known in advance, you can examine the Bands property in code. Allowable band numbers range from 0 to Bands-1.

The following events enable your application to respond to hierarchical view operation initiated by the user:

Collapse

Fired when a band is collapsed by a user

Expand

Fired when a band is expanded by a user

 

 


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

Product Support Forum  |  Documentation Feedback