Example E633
Visible to All Users

Reporting for WinForms - How to Calculate Grand Total for Detail Report Summaries

This example calculates grand total summary for detail reports.

In this example, the report is bound to a dataset that has two related tables - the Customers table for the main report, and the Orders table for the DetailReport band.

The detail report calculates the sum of the Freight columns for each customer. This summary is calculated automatically in the xrlFreightTotal label in the detail report footer.

The grand total of the Freight summaries is displayed in the main report. This summary cannot be calculated automatically, because the Freight column does not belong to the main report data source. To solve the problem, the SummaryCalculated event of summary labels in a detail report is handled. Note that when the BeforePrint event occurs, a summary value is not yet calculated. Use the SummaryCalculated event to obtain a calculated summary value. The summary amounts of the individual detailed reports are summed up in a global variable (GrandTotals), which is then printed in the footer of the main report.

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Form1.cs(vb)
C#
using System; using System.Windows.Forms; using DevExpress.XtraReports.UI; // ... namespace DetailReportsSum { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { XtraReport1 report = new XtraReport1(); ReportPrintTool printTool = new ReportPrintTool(report); printTool.ShowPreview(); } } }
Program.cs(vb)
C#
using System; using System.Collections.Generic; using System.Windows.Forms; namespace DetailReportsSum { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }
XtraReport1.cs(vb)
C#
using System; using DevExpress.XtraReports.UI; // ... namespace DetailReportsSum { public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport { public XtraReport1() { InitializeComponent(); } decimal GrandTotals = 0; private void xrlFreightTotal_SummaryCalculated(object sender, TextFormatEventArgs e) { if(e.Value != null) GrandTotals += Convert.ToDecimal(e.Value); } private void xrlFreightGrandTotal_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) { xrlFreightGrandTotal.Text = string.Format("{0:c2}", GrandTotals); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.