Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [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]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
   [Expand]Getting Started
   [Expand]RichEditControl Document
   [Expand]Fields
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Printing
    Spell Checking
    AutoCorrect
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
    Traversing the Document
   [Expand]Visual Elements
    Services
    Events
    Commands
   [Expand]Member Tables
    Keyboard Shortcuts
    HTML Tag Interpretation
   [Collapse]Examples
    [Expand]Files
    [Expand]Text
    [Expand]Formatting
    [Expand]Styles
    [Expand]Lists
    [Expand]Pictures
    [Expand]Text Boxes
    [Expand]Tables
    [Expand]Layout
    [Expand]Automation
    [Expand]Search and Replace
    [Collapse]Mail Merge
      How to: Perform a Mail Merge
      How to: Create a Master-Detail Report
    [Expand]Spell Check
    [Expand]Export-Import
    [Expand]Printing
    [Expand]Protection
    [Expand]User Interface Customization
    [Expand]Miscellaneous
    [Expand]Commands
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap 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]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Create a Master-Detail Report

This tutorial describes an alternative approach to creating Master-Detail documents using the RichEditDocumentServer's Mail Merge implementations.

Important

The SnapControl and SnapDocumentServer components provide an improved approach to Mail Merge. Refer to the Snap Mail Merge topic for details.

In this example, the report is generated using three templates: Main, Master, and Detail, containing DOCVARIABLE fields. A RichEditDocumentServer instance is created on each data level for holding the corresponding template and for calculating in the Document.CalculateDocumentVariable event handler. As a result, all intermediate documents are combined into a single report, which is passed to the parent document to substitute the initial DOCVARIABLE field.

The following image displays the result:

The steps below provide more detailed information about how to process each part of a master-detail report.

Expanded Main Template

The main template is the document without MERGEFIELD fields. It may contain a logo, standard header and footer, and all the parts required for a corporative design and layout. The template's DOCVARIABLE field indicates where the Master template is inserted. Use the FieldCollection.Create method to insert a field into the desired position in the document.

Initiate the mail merge process with empty data. Assign the control to a mock data source and call the Document.MailMerge method with the resulting control's document or a file set as the destination (in this example, the result is passed to the resultRichEdit).

Show Me

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

Expanded Master Template

The destination control receives the Main document and fires the RichEditControl.CalculateDocumentVariable event. Handle this event the following way to create a master part and insert it into the document:

  1. Make sure that the event is fired for the required field (by checking the CalculateDocumentVariableEventArgs.VariableName value);

  2. Use the MailMergeOptions.DataSource property to provide the Master template's data source;

  3. Call the RichEditControl.CreateDocumentServer method to create a Document Server implementing the IRichEditDocumentServer interface. The Document Server is required to create a report and pass it to the event sender using the CalculateDocumentVariableEventArgs.Value property;

  4. Subscribe the create document server instance to the RichEditControl.CalculateDocumentVariable event to process the detail part of the report;
  5. Call the Document.MailMerge method to merge the Master template and obtain the source document with the corresponding data;

Show Me

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

Expanded Detail Template

After the mail merge, the document created from the Master template is loaded into the Document Server, and the RichEditControl.CalculateDocumentVariable event fires. Handle the event to compose the Detail template:

  1. Make sure that the event is fired for the required field (by checking the CalculateDocumentVariableEventArgs.VariableName value);

  2. Use the MailMergeOptions.DataSource property to assign a data source to the Detail template;

  3. Call the RichEditControl.CreateDocumentServer method to create a new Document Server;

  4. This template contains a master-detail table header. The resulting table is composed of separate tables. Use the MergeMode.JoinTables option to make the tables continuous. When not using tables, assigning this value to the MailMergeOptions.MergeMode property results in an incorrect layout;

  5. Subscribe the current RichEditDocumentServer instance to the Document.CalculateDocumentVariable event for further processing. This step is required if the Detail template contains any DOCVARIABLE fields. In this example, the Document.CalculateDocumentVariable event is used to insert and format the UnitPrice field.

  6. Call the Document.MailMerge method to merge the Detail template.

Show Me

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

Expanded See Also

How would you rate this topic?​​​​​​​