Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Sort Group Rows by Summary Values

The following example shows how to sort the group rows that reside at the first grouping level by summary values. The group summaries are calculated by the Freight column’s values.

The image below shows the result.

SummarySortInfo

using DevExpress.Data;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;

GridSummaryItem summaryItemMaxFreight;
private void Form1_Load(object sender, System.EventArgs e) {
   // ...
   //  Creating a new summary item and adding it the view's summary item collection.
   summaryItemMaxFreight = gridView1.GroupSummary.Add(SummaryItemType.Max, 
     "Freight", null, String.Empty);
}

private void button1_Click(object sender, System.EventArgs e) {
   GridColumn summaryColumn = gridView1.Columns["Freight"];
   if(summaryColumn.GroupIndex < 0 && gridView1.GroupCount > 0) {
      GridColumn firstGroupingColumn = gridView1.SortInfo[0].Column;
      gridView1.GroupSummarySortInfo.Add(summaryItemMaxFreight, 
        ColumnSortOrder.Ascending, firstGroupingColumn);
   }
}