Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Collapse]Reporting
 [Expand]Product Information
 [Expand]Getting Started
 [Expand]Fundamental Concepts
 [Collapse]Concepts
  [Expand]Report Types
  [Expand]Report Controls
  [Expand]Platform-Specific Reporting
  [Collapse]Creating Reports
   [Expand]Providing Data to Reports
   [Expand]Providing Data To Report Controls
   [Collapse]Shaping Data
     Grouping Data
     Sorting Data
     Filtering Data
     Calculating Summaries
     Formatting Data
   [Expand]Using Report Parameters
   [Expand]Appearance Customization
   [Expand]Navigation and Interaction
   [Expand]Scripting
  [Expand]Storing Reports
  [Expand]Publishing Reports
  [Expand]End-User Reporting
  [Expand]Application Appearance
  [Expand]Migration to XtraReports
 [Expand]Design-Time Features
 [Expand]Examples
  End-User Capabilities
 [Expand]Localization
 [Expand]Redistribution and Deployment
 [Expand]API Reference
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
[Expand]End-User Documentation

Grouping Data

This topic gives you a general overview of grouping data in XtraReports, and provides design-time and runtime samples. Grouping allows you to split data into groups based on identical values in a field or fields. Note that grouping can only be applied to bound reports.

This document consists of the following sections.

Expanded Grouping Overview

To enable grouping in your report, a GroupHeaderBand should be added to it. It can be accompanied by a GroupFooterBand, that is associated with the GroupHeader using the GroupBand.Level property, whose value should be identical for the group header and footer. The GroupHeader and GroupFooter bands are printed as many times as there are distinct combinations of grouping fields.

For this reason, at least one GroupField object (a grouping criteria) should be added to the group fields collection of the GroupHeader band using its GroupHeaderBand.GroupFields property. For a group field, define its GroupField.FieldName property, which determines the name of the data member upon which grouping is performed.

A group field's data member can be obtained from the object, which is specified by the XtraReportBase.DataSource and XtraReportBase.DataMember properties.

When the report data source is not defined at design time, you can specify a static value for the FieldName property of a GroupField.

A calculated field can be defined as a group field as well, allowing you to perform grouping based on complex conditions. To learn more, see How to: Group Data by a Custom Field.

At design time within Visual Studio (or in the End-User Designer), the easiest way to group data is to use the Group and Sort panel.

For detailed steps on using it, see How to: Group Data.

By default, when XtraReports groups data in a data source against a specified group field, it also sorts data against this field. The sorting order (ascending or descending) is specified by the GroupField.SortOrder property. To disable sorting in grouped data, set this property to None.

Note

Groups can be sorted by a summary function result. For information, see Sorting Data.

Data can be grouped by multiple data fields in two different ways.

  1. Creating a single GroupHeaderBand and assigning multiple group fields to its GroupHeaderBand.GroupFields collection. This way, data will be grouped by the distinct combinations of these group fields' values.

  2. Creating multiple GroupHeaderBand objects, and specifying different group fields for each of these group bands. In this case, we'll get nested grouping of the report data. In this scenario, the nesting level is determined by GroupHeaders' GroupBand.Level property: the greater its value, the higher level a GroupHeader has. Note that it's impossible to assign an identical value to this property for different group headers; setting this property for one GroupHeader band causes this property to auto-adjust other GroupHeaders simultaneously.

The images below illustrate these two methods of multiple grouping.

GroupHeader band with multiple group fields Nested GroupHeader bands

Expanded Grouping Options

When grouping data, the following options are available.

  • Groups Layout

    Use the GroupHeaderBand.GroupUnion property to specify whether group rows can be printed on different pages (in this case both GroupHeaderBand.GroupUnion and GroupFooterBand.GroupUnion are set to None), or the entire group will be printed on a single page (if the GroupHeaderBand.GroupUnion property is set to WholePage).

    If, however, a group is allowed to be split across pages, but you don't want a GroupHeader to be printed on a page if there is no data row below it (in case a group starts at the bottom of the page and there is enough room for only a GroupHeader), you may set the GroupHeaderBand.GroupUnion property to WithFirstDetail. In this case, if a GroupHeader is alone on a page, it will be moved to the beginning of the next page.

    To decide whether a group band can be split across pages, use its Band.KeepTogether property, which specifies whether the contents of the band can be horizontally split across pages. In other words, if the content of the band is larger than the remaining space on the page, this property specifies whether the band's content should be split across the current page and the next page, or whether the band will be printed in its entirety on the next page. Note that this property is in effect only when a band's contents do not fit onto the current page.

    If the band still can't be printed in it's entirety on the next page (there isn't enough space to keep all the band contents together), then it will be split as though this property's value is set to false.

  • Group Header Occurrence

    To decide whether a group band should be shown only on the first page that the group appears, or on every page that the group is printed on, use the GroupBand.RepeatEveryPage property. Note that this property works independently for the GroupHeaderBand and GroupFooterBand objects of the same group.

  • Page Numbering

    To make your report display page numbers for individual groups, place the XRPageInfo control onto the GroupHeader (or GroupFooter) band, and set its XRPageInfo.RunningBand property to the name of the GroupHeader band.

    Note that for accurate page numbering, multiple groups should not appear simultaneously on the same page. To ensure this, set the GroupHeader's Band.PageBreak property to AfterBand, or place the XRPageBreak control at the band's bottom. For more information on this, refer to How to: Insert Page Numbers for Groups.

Expanded Examples

Expanded See Also

How would you rate this topic?​​​​​​​