[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
   [Expand]Getting Started With Data Grid and Views
   [Expand]Data Binding
    Unbound Columns
   [Expand]Views
   [Expand]Data Editing and Validation
   [Expand]Grouping
   [Expand]Sorting
   [Expand]Filter and Search
   [Collapse]Summaries
     Working with Summaries in Code. Custom 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
   [Expand]Scrolling
   [Expand]Batch Modifications
   [Expand]Hit Information
    Hints
    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]Property 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]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Working with Summaries in Code. Custom Summaries

Expanded Create Total Summaries

This example demonstrates how to add three total summaries with different types and aggregate functions.

Open the Manual total summary live demo and remove its code from the "ExampleCode" tab. Create three GridSummaryItem objects:
  • a summary item for displaying total record count - does not require setting the GridSummaryItem.FieldName property;
  • a summary item for calculating an average length - utilizes a custom {0:#.#} display format;
  • a summary item with a custom aggregate function.

For the third summary item, you need to provide a custom aggregate function that calculates the summary value. To do so, handle the GridView.CustomSummaryCalculate event. The code sample below determines if the processed order belongs to the current week, and if so, increments the summary.

Add all three summary items to the GridColumn.SummaryItem collections of required columns and explicitly show the View footer by enabling the GridOptionsView.ShowFooter setting.

Expanded Create Group Summaries

The code below creates three group summaries. You can test this sample in the Manual total summary demo.

  • a "Count" summary displayed in group rows;
  • an "Average" summary shown in group footer area;
  • a group footer summary with a custom aggregate function.

To add group summaries in code, you need to either manually create GridGroupSummaryItem objects and place them inside the GridView.GroupSummary collection, or call the collection's Add method with required parameters.

A summary with a custom aggregate function requires handling the GridView.CustomSummaryCalculate event to calculate a summary value.

Expanded Obtain Summary Values

Utilize the following API to retrieve summaries, their values and displayed text.

Common API

GridSummaryItem.SummaryValue
Gets the value of this summary item.

GridSummaryItem.GetDisplayText
Applies the current display format rule expression to convert any value into a display text.

Total Summaries

GridColumn.SummaryText
Returns the text displayed by total summaries owned by this column. The return value is a single string that delimits values of separate summaries with the "\r\n" sequence (e.g., "Max: 1007.6400\r\n830 records").

Group Summaries

GridView.GetRowSummaryItem
Takes a row handle and a column as parameters and returns a DictionaryEntry object that provides access to:
  • a summary item associated with these row and column - accessed through the DictionaryEntry.Key property;
  • a summary item's value - accessed through the DictionaryEntry.Value property.
The code sample below retrieves a group summary item text whenever the focused row changes.

GridView.GetGroupSummaryValue, GridView.GetGroupSummaryDisplayText
Return the value and the display text of the specific group summary item for a specific group.

GridView.GetGroupSummaryValues
Returns the hashtable that stores pairs of summary items (keys) and their values (values) for the given row handle. The hashtable contains entries for summary items displayed in both group footers and group rows.

GridView.GetGroupSummaryText
Returns the text, displayed by group summary items in a group row.

GridView.GetRowFooterCellText
Call this method to retrieve text, displayed by a specific summary item in a group footer.

Example

The following code utilizes summary access API to perform the following customizations:
  • groups with more than three child items are highlighted with red;
  • display text of total summaries is changed without modifying these summaries' display formats.

Expanded See Also

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