Do the following to create a hierarchical report in code:
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 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.
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.
Do the following to allow end users to expand and collapse tree nodes:
-
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.
-
Set the DetailBand's DrillDownControl property to the added XRCheckBox control.
-
Set the XRCheckBox's CheckState property to the following expression: [ReportItems].[Detail].[DrillDownExpanded]
In this example, the DetailBand's SortFields property is specified to sort data on each hierarchy level.
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.
- Create a Hierarchical Report](https://docs.devexpress.com/XtraReports/400925/create-popular-reports/create-a-hierarchical-report)