Sort Data (Runtime Sample)

This sample demonstrates how to sort report data at runtime. In the report created in this example, products are sorted by their names in ascending order:

HowTo_SortData_1

To sort a report's data in code, create a GroupField object and add it to the DetailBand.SortFields collection in the report's XRControl.BeforePrint event handler.

using System;
using System.Drawing;
using DevExpress.XtraReports.UI;
// ...

private void XtraReport1_BeforePrint(object sender, Printing.PrintEventArgs e) {
    Detail.SortFields.Add(new GroupField("ProductName", XRColumnSortOrder.Ascending));
}
TIP

See Sort Data by a Custom Field to learn how to implement custom logic for sorting report data.