Skip to main content

XRLabel.SummaryCalculated Event

Occurs when the automatic summary value of a label has been calculated.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public event TextFormatEventHandler SummaryCalculated

Event Data

The SummaryCalculated event's data class is TextFormatEventArgs. The following properties provide information specific to this event:

Property Description
Format Gets the formatting string applied to the summary’s text.
Text Gets or sets the text representation of the summary TextFormatEventArgs.Value with the string formatting applied.
Value Gets the value which is automatically calculated as the label’s summary.

Remarks

Use this event to obtain a summary value which is automatically calculated for a label control. This value can be accessed via the TextFormatEventArgs.Value property.

Note: This event is useful when a grand total needs to be calculated for all the detail reports in a master report, as this value can’t be calculated automatically in XtraReports.

Example

This example demonstrates how to use the XRLabel.SummaryCalculated event for a label control. In this example, the report’s dataset contains two related tables. The Categories table is bound to the main report, and the Products table is used as the DetailReport’s data source, which gives a list of products by categories.

The detail report calculates the sum of the UnitPrice column for each product. This summary is calculated automatically. The grand total of the UnitPrice summaries must be displayed in the main report. You have to write your own code to calculate this kind of summary. It cannot be calculated automatically, because the UnitPrice column does not belong to the main report’s data source.

You should handle the SummaryCalculated event of summary labels in your detail report. Please note that when the BeforePrint event is fired, a summary value has not yet been calculated; you should use SummaryCalculated to obtain a calculated summary value. The summaries of individual detail reports are incremented in a global variable (GrandTotals), which is then printed in the main report’s footer.

using System.Drawing.Printing;
using DevExpress.XtraReports.UI;
// ...

// Grand total value.
double GrandTotals = 0;

// Add the summary value to the grand total.
private void lbUnitPriceTotal_SummaryCalculated(object sender, TextFormatEventArgs e) {
   if(e.Value != null)
      GrandTotals += Convert.ToDouble(e.Value);
}

// Set the grand total value to the label's text.
private void lbUnitPriceGrandTotal_BeforePrint(object sender, CancelEventArgs e) {
   ((XRLabel)sender).Text = GrandTotals.ToString();
}
See Also