[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Collapse]Get Started With Data Grid and Views
     [Expand]Appearance and Conditional Formatting
     [Expand]Data Editing
     [Expand]Hit Information
     [Expand]Data Binding and Working with Columns
     [Expand]Grid View - Columns, Rows and Cells
     [Expand]Banded Views
     [Expand]WinExplorer View
     [Expand]Tile View
     [Expand]Filter and Search
       Tutorial: Custom Summary Functions
       Tutorial: Format Summary Text
       Tutorial: Group Summaries
       Tutorial: Obtain Summary Values
       Tutorial: Sort Group Rows by Summary Values
       Tutorial: Total Summaries
     [Expand]Split Presentation
     [Expand]Row Preview Sections
   [Expand]Data Binding
    Unbound Columns
   [Expand]Data Editing and Validation
   [Expand]Filter and Search
   [Expand]Focus and Selection Handling
    Format Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
   [Expand]Batch Modifications
    Hit Information
    Popup Menus
   [Expand]Save and Restore Layout
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Tutorial: Sort Group Rows by Summary Values

This walkthrough is a transcript of the Sort Group Rows by Summary Values video available on the DevExpress YouTube Channel.

The tutorial first shows the grid's built-in UI allowing you to sort group rows by summary values. You will then see how to disable this UI if needed, and how you can sort group rows in code.

Launch demo: Sorting by Summary Values

Expanded Starting Point

Start with a GridControl already grouped against the Category column.

By default, group rows are automatically sorted in alphabetical order where the "Beverages" group row is followed by "Condiments", then by "Confections" and so on.

Expanded Adding a Group Summary

In the form Load event handler, create a group summary that calculates the maximum value in the OrderSum column. The summary values will be displayed in group rows.

Run the application. Group rows display the maximum values of the OrderSum column within each group.

Expanded End-User Capabilities

Right-click the Category column header, select the Sort by Summary item, and then Sort Ascending.

As a result, group rows are now sorted in ascending order based on summary values. A special glyph displayed within the grouping column indicates the current sort order.

In the same manner, you can reverse the sort order. To remove group row sorting, right-click the Category column header and select Clear Summary Sorting.

Expanded Restricting End-User Capabilities

Select the grid View, expand its GridView.OptionsMenu property and disable the GridOptionsMenu.ShowGroupSortSummaryItems option.

Run the application and right-click the Category column's header. The context menu that appears now as a result doesn't contain the Sort by Summary item.

Expanded Sorting by Summary Values in Code

Close the application again and return to the form Load event handler. Obtain the first grouping column from the View's ColumnView.SortInfo collection. To sort group rows in code, create a new GroupSummarySortInfo object. Use the summary item, target column and required sort order as parameters. Finally, clear the GridView.GroupSummarySortInfo collection and add the created object to it using the GroupSummarySortInfoCollection.ClearAndAddRange method.

Run the application to see the result. Group rows will now be sorted by summary values in ascending order.

Expanded See Also

Is this topic helpful?​​​​​​​