Back to Devexpress

Sort Data (Runtime Sample)

xtrareports-8822-feature-guide-to-devexpress-reports-shape-report-data-group-and-sort-sort-data-runtime-sample.md

latest1.5 KB
Original Source

Sort Data (Runtime Sample)

  • Feb 18, 2026

This code sample demonstrates how to sort report data at runtime. In this example, the report’s DetailBand is bound to the Products table of the sample Northwind database. The products are sorted by their names in ascending order:

To sort report data in code, create the GroupField object and add it to the DetailBand.SortFields collection:

csharp
using DevExpress.XtraReports.UI;
// ...
    TestReport rep = new TestReport();
    DetailBand detail = rep.Bands[BandKind.Detail] as DetailBand;
    detail.SortFields.Add(new GroupField("ProductName"));
vb
Imports DevExpress.XtraReports.UI
' ...
    Dim rep As New TestReport()
    Dim detail As DetailBand = TryCast(rep.Bands(BandKind.Detail), DetailBand)
    detail.SortFields.Add(New GroupField("ProductName"))

You can use the calculated field to implement custom logic to sort the report data. For more information, review the following help topic: Sort Data by Custom Criteria.