Skip to content

DevExpress-Examples/reporting-winforms-create-hierarchical-report-in-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reporting for WinForms - How to create a Hierarchical Report in Code

Hierarchical Report

Implementation Details

Do the following to create a hierarchical report in code:

Bind Report to Data

You can print a report in tree mode if it is bound to recursive data or data with ID-ParentID related fields. In this example, data records are defined by the CountryData class.

Specify Hierarchy Print Options

Specify either the HierarchyPrintOptions.ChildListFieldName property (for recursive data) or the HierarchyPrintOptions.KeyFieldName-HierarchyPrintOptions.ParentFieldName property pair (for ID-ParentID related data fields, like in this example) to print the report's DetailBand.

Specify the HierarchyPrintOptions.Indent property to set the child node offset, in report units.

Align Tree Nodes

In this example, the AnchorHorizontal property of the DetailBand's labels is set to Both. This allows the labels to fit the page. See the HierarchyPrintOptions class description for details.

Add a Control to Expand/Collapse Tree Nodes

Do the following to allow end users to expand and collapse tree nodes:

  1. Add the XRCheckBox control to the DetailBand at the left-most position. In this example, the checkbox' GlyphOptions property is used to specify custom glyphs for the checked and unchecked states.

  2. Set the DetailBand's DrillDownControl property to the added XRCheckBox control.

  3. Set the XRCheckBox's CheckState property to the following expression: [ReportItems].[Detail].[DrillDownExpanded]

Sort Report Data

In this example, the DetailBand's SortFields property is specified to sort data on each hierarchy level.

Highlight Root Nodes

When the CurrentRowHierarchyLevel variable in expressions to get a row's zero-based level in the tree. In this example, this variable is used in the DetailBand's expression to set the background color for the top-level nodes.

Files to Review

Documentation