Skip to main content
A newer version of this page is available.
All docs
V18.2

Simulate the Mail Merge Feature for Summary Fields

  • 2 minutes to read

When shaping report data, you may require summary fields to display information from a data source in addition to the summary result, allowing you to simulate the mail merge feature. This tutorial describes how to simulate the mail merge feature for the summary fields at runtime.

  1. Group the report’s data by the CategoryID data field, for instance, using the Group and Sort panel. Enable the Show Footer check box to add a GroupFooter band for displaying a summary at the bottom of each group.

    How to - CalculateCustomSum_0a

  2. Drop the ProductName field from the Field List onto the created band.
  3. Click the created label’s smart tag, and set its XRSummary.Running property to Group, and the XRSummary.Func property to Count.

    HowTo_SimulateMailMerge_1

  4. Bind the label’s XRControl.Tag property to the CategoryID data field.

    HowTo_SimulateMailMerge_1a

  5. Handle this label’s XRLabel.SummaryCalculated event.

    HowTo_SimulateMailMerge_2

    Paste the following code to the event handler.

    using System;
    using DevExpress.XtraReports.UI;
    // ...
    
    private void xrLabel2_SummaryCalculated(object sender, TextFormatEventArgs e) {
        e.Text = String.Format("Category #{0} contains {1} items.", ((XRLabel)sender).Tag, e.Value);
    }
    

The mail-merge report is now ready. Run the Print Preview form and view the result.

HowTo_SimulateMailMerge_3