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
- Form1.cs (VB: Form1.vb)
- Program.cs (VB: Program.vb)
- XtraReport1.cs (VB: XtraReport1.vb)
Documentation
More Examples
- Reporting for WinForms - How to Create a Report with Running Totals
- How to sort groups by a custom summary function result
- How to create a summary programmatically
- How to calculate a total of different summary functions' results
- How to calculate an aggregated summary function
- How to conditionally suppress summary footer cell painting by using formatting rules
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
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();
}
}
}
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());
}
}
}
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);
}
}
}