[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
  [Expand]Data Grid
  [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]Product Information
   [Expand]Getting Started
   [Expand]Fundamental Concepts
    [Expand]Print Preview
    [Expand]Using Bricks
    [Expand]Using Printing Links
    [Expand]Page Header and Footer
    [Expand]Printing DevExpress Controls
      How to: Create an Interactive Drill-Down Report
      How to: Create a Document Map (Bookmarks)
      How to: Calculate Page and Report Summaries
      How to: Add a Watermark to a Document
      How to: Save and Restore a Document's Watermark in Print Preview
      How to: Add Different Watermarks to Document Pages
  [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)

How to: Calculate Page and Report Summaries

This topic illustrates the use of PrintingSystem events to adjust the displayed information when page contents are changed due to margin or page size modifications.

The task is to implement summary fields that only calculate those values in the table which fall on one page. So, when the page size or margins are modified and the table with values becomes split across several pages, these summaries count values on each page. The page footer is a good place to put those fields.

The Summaries demo application in a demo suite for XtraPrinting Library provides an example of how this problem can be solved. Here, we point out methods used in this solution.

The report created in this application contains two columns with pseudo-random values. They are generated in the Detail section of the report. Each TextBrick containing a random value is marked as belonging to either the "Count" or "Sum" column. It is accomplished by assigning the ID property value. The ReportFooter section at the bottom displays two different summary types - item count and item sum, which are calculated when text bricks are generated and added to the Details area.

To represent the dynamic summaries, we create two text bricks in the BrickModifier.MarginalFooter page area and place them into an array for easy access when necessary. We choose the PrintingSystemBase.BeforePagePaint event of the PrintingSystem to perform a new summary calculation. It forces the recalculation each time a page is redrawn. The code of the custom PagePainting procedure, which handles this event, is presented below. It iterates the bricks on a current page, filters them by their identifier, performs the necessary calculations and puts the results into text bricks previously created in the MarginalFooter. To get access to the current page's bricks, the CompositeBrick.GetEnumerator method can be used, and in code it is represented with the foreach statement.

The resulting report is shown in the following pictures. The first picture displays the report fitted onto one page, the second illustrates the situation when page size and margins are reduced, so the report is split into two pages.


A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E18.

Expanded See Also

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