Skip to main content
A newer version of this page is available. .

GroupHeaderBand Class

A report band used for specifying grouping criteria and displaying information at the beginning of a group of records.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v19.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public class GroupHeaderBand :
    GroupBand,
    IDrillDownNode

Remarks

Use the GroupHeaderBand.GroupFields property to specify grouping criteria for the report’s data.

Tip

A corresponding GroupFooterBand should have the same GroupBand.Level property value as the group header.

See the following topics for more details:

See Laying out Dynamic Report Contents to learn about the layout options available for this band.

Example

The report created in this example is bound to the CategoryProducts view of the sample Northwind database (the nwind.mdb file located in the directory, where you installed DevExpress demos).

This report contains two bands: DetailBand and GroupHeaderBand, and the Group Header band groups data by the “CategoryName” data field.

At runtime, data grouping can only be done prior to a report document is being created. To group data just before a report is printed/previewed, use the XRControl.BeforePrint event.

Please make sure to include all necessary assemblies to the References list of your project.

using System;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
using DevExpress.XtraReports.Configuration;
// ...

public XtraReport CreateDataGroupingReport() {
    // Create a report.
    XtraReport report = new XtraReport();

    // Create a data source with the required connection parameters.  
    Access97ConnectionParameters connectionParameters =
        new Access97ConnectionParameters("../../nwind.mdb", "", "");
    SqlDataSource ds = new SqlDataSource(connectionParameters);   
    CustomSqlQuery query = new CustomSqlQuery();
    query.Name = "customQuery";
    query.Sql = "SELECT * FROM CategoryProducts";
    ds.Queries.Add(query);
    ds.RebuildResultSchema();

    // Assign the data source to the report.
    report.DataSource = ds;
    report.DataMember = "customQuery";

    // Create a detail band and add it to the report.
    DetailBand detail = new DetailBand { HeightF = 40 };
    report.Bands.Add(detail);

    // Create a group header band and add it to the report.
    GroupHeaderBand ghBand = new GroupHeaderBand { HeightF = 40 };
    report.Bands.Add(ghBand);

    // Create a group field and assign it to the group header band.
    GroupField groupField = new GroupField("CategoryName");
    ghBand.GroupFields.Add(groupField);

    // Create new labels.
    XRLabel labelGroup = new XRLabel { ForeColor = System.Drawing.Color.Blue };
    XRLabel labelDetail = new XRLabel { LocationF = new System.Drawing.PointF(30, 0) };

    // Specify labels' bindings depending on the report's data binding mode.
    if (Settings.Default.UserDesignerOptions.DataBindingMode == DataBindingMode.Bindings) {
        labelGroup.DataBindings.Add("Text", null, "customQuery.CategoryName");
        labelDetail.DataBindings.Add("Text", null, "customQuery.ProductName");
    } else {
        labelGroup.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[CategoryName]"));
        labelDetail.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[ProductName]"));
    }
    // Add these labels to the report's bands.    
    ghBand.Controls.Add(labelGroup);          
    detail.Controls.Add(labelDetail);

    return report;
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the GroupHeaderBand class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

Implements

DevExpress.XtraPrinting.IBrickOwner
DevExpress.Utils.Serializing.Helpers.IXtraSupportDeserializeCollectionItem
DevExpress.Utils.Serializing.IXtraSerializable
See Also