Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [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]Getting Started
    [Collapse]Walkthroughs
     [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
     [Collapse]Grouping
       Tutorial: Custom Grouping Algorithms
       Tutorial: Group Row API
       Tutorial: Grouping Basics
     [Expand]Filter and Search
     [Expand]Sorting
     [Expand]Summaries
     [Expand]Split Presentation
     [Expand]Row Preview Sections
     Data Grid and Views
   [Expand]Data Binding
   [Expand]Views
   [Expand]Data Editing and Validation
   [Expand]Grouping
   [Expand]Sorting
   [Expand]Filter and Search
   [Expand]Summaries
   [Expand]Focus and Selection Handling
    Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
    Scrolling
   [Expand]Batch Modifications
   [Expand]Hit Information
    Hints
   [Expand]Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap 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]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Tutorial: Custom Grouping Algorithms

This walkthrough is a transcript of the Custom Grouping Algorithms video available on the DevExpress YouTube Channel.

By default, data groups are formed by putting identical values into each group. Although the grid provides a few other built-in algorithms, sometimes you need to implement your own logic, which is done using the GridView.CustomColumnGroup event. You will learn how to handle this event in order to change a numeric column's data grouping logic so that groups contain ranges of values starting with 0 to 99.99, then 100 to 199.99 and so on.

Expanded Default Behavior

When you group the grid's data against the Order Sum column, by default, groups are formed based on unique values in that column.

Expanded Implementing Custom Grouping Logic

Switch to design-time and first of all, enable custom sorting mode for this column by setting the GridColumn.SortMode property to ColumnSortMode.Custom.

After that, select the grid View and handle its GridView.CustomColumnGroup event. The column being processed is specified by the event's CustomColumnSortEventArgs.Column parameter. The event handler compares two rows with values specified by the CustomColumnSortEventArgs.Value1 and CustomColumnSortEventArgs.Value2 parameters. Since you combine values into groups corresponding to hundreds, divide the values by 100 and compare the results. To place all values above 1000 into the same group, the handler assumes that results are equal if they are both greater than 10. The CustomColumnSortEventArgs.Result parameter is set to 0 in that case. Other values undergo standard comparison.

The event's CustomColumnSortEventArgs.Handled parameter is set to true to prevent the default comparison mechanism from being invoked after event execution.

To better illustrate how this code works, the grouping column values should be visible even when data is grouped. To enable this behavior, expand GridView.OptionsView and set the GridOptionsView.ShowGroupedColumns option to true.

Now run the application and group grid data by the Order Sum column. As a result, rows are combined into the specified intervals. However, group rows display the first value in a corresponding group, thus misleading end-users. This can also be fixed.

Expanded Providing Custom Display Text for Group Rows

Return to design time and subscribe to the ColumnView.CustomColumnDisplayText event. Check the event's CustomColumnDisplayTextEventArgs.Column and CustomColumnDisplayTextEventArgs.IsForGroupRow parameters. The first parameter specifies the column currently being processed, while the second parameter indicates whether the event is called to customize group row display text. The CustomColumnDisplayTextEventArgs.GroupRowHandle parameter returns the currently processed group row. To change the group row's display text, use the event's CustomColumnDisplayTextEventArgs.DisplayText parameter.

Run the application and group data by the Order Sum column once again. Group rows will now display custom text that correctly identifies the intervals.

Expanded See Also

How would you rate this topic?​​​​​​​