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:
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));
}
Imports System
Imports System.Drawing
Imports DevExpress.XtraReports.UI
' ...
Private Sub XtraReport1_BeforePrint(ByVal sender As Object, _
ByVal e As PrintEventArgs) Handles MyBase.BeforePrint
Detail.SortFields.Add(New GroupField("ProductName", XRColumnSortOrder.Ascending))
End Sub