xtrareports-devexpress-dot-xtrareports-dot-ui-dot-groupheaderband.md
Gets a collection of GroupField objects used as the criteria for creating groups in a report.
Namespace : DevExpress.XtraReports.UI
Assembly : DevExpress.XtraReports.v25.2.dll
NuGet Package : DevExpress.Reporting.Core
[SRCategory(ReportStringId.CatBehavior)]
public GroupFieldCollection GroupFields { get; }
<SRCategory(ReportStringId.CatBehavior)>
Public ReadOnly Property GroupFields As GroupFieldCollection
| Type | Description |
|---|---|
| GroupFieldCollection |
A GroupFieldCollection object.
|
View Example: How to group data at runtime
The report created in this example uses the sample Northwind database.
The report is bound to the SQL data source, which retrieves data from the CategoryProducts database view.
This report contains two bands: the Detail band and the Group Header band. The Group Header band includes a group field that specifies that the data is grouped by the CategoryName data field.
Tip
You can handle the XRControl.BeforePrint event to change data grouping before a report is printed or previewed.
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 specified connection parameters.
SQLiteConnectionParameters connectionParameters =
new SQLiteConnectionParameters() {
FileName = "nwind.db",
Password = null
};
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 the Detail band and add it to the report.
DetailBand detail = new DetailBand { HeightF = 40 };
report.Bands.Add(detail);
// Create the Group Header band and add it to the report.
GroupHeaderBand ghBand = new GroupHeaderBand { HeightF = 40 };
report.Bands.Add(ghBand);
// Create a GroupField instance and add it to the Group Header band.
GroupField groupField = new GroupField("CategoryName");
ghBand.GroupFields.Add(groupField);
// Create labels.
XRLabel labelGroup = new XRLabel { ForeColor = System.Drawing.Color.Blue };
XRLabel labelDetail = new XRLabel { LocationF = new System.Drawing.PointF(30, 0) };
// Specify label bindings.
labelGroup.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[CategoryName]"));
labelDetail.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[ProductName]"));
// Add the labels to the report's bands.
ghBand.Controls.Add(labelGroup);
detail.Controls.Add(labelDetail);
return report;
}
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraReports.UI
Imports DevExpress.DataAccess.ConnectionParameters
Imports DevExpress.DataAccess.Sql
Imports DevExpress.XtraReports.Configuration
' ...
Public Function CreateDataGroupingReport() As XtraReport
' Create a report.
Dim report As XtraReport = New XtraReport()
' Create a data source with the specified connection parameters.
Dim connectionParameters As SQLiteConnectionParameters = New SQLiteConnectionParameters() With {
.FileName = "nwind.db",
.Password = Nothing
}
Dim ds As SqlDataSource = New SqlDataSource(connectionParameters)
Dim query As CustomSqlQuery = 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 the Detail band and add it to the report.
Dim detail As DetailBand = New DetailBand With {.HeightF = 40}
report.Bands.Add(detail)
' Create the Group Header band and add it to the report.
Dim ghBand As GroupHeaderBand = New GroupHeaderBand With {.HeightF = 40}
report.Bands.Add(ghBand)
' Create a GroupField instance and add it to the Group Header band.
Dim groupField As GroupField = New GroupField("CategoryName")
ghBand.GroupFields.Add(groupField)
' Create labels.
Dim labelGroup As XRLabel = New XRLabel With {.ForeColor = System.Drawing.Color.Blue }
Dim labelDetail As XRLabel = New XRLabel With {.LocationF = New System.Drawing.PointF(30, 0)}
' Specify label bindings.
labelGroup.ExpressionBindings.Add(New ExpressionBinding("BeforePrint", "Text", "[CategoryName]"))
labelDetail.ExpressionBindings.Add(New ExpressionBinding("BeforePrint", "Text", "[ProductName]"))
' Add the labels to the report's bands.
ghBand.Controls.Add(labelGroup)
detail.Controls.Add(labelDetail)
Return report
End Function
See Also