Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

RichEditDocumentServer.MailMergeRecordStarted Event

Fires before each data record is merged with the document in the mail merge process.

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.RichEdit.v22.1.Core.dll

NuGet Package: DevExpress.RichEdit.Core

Declaration

public event MailMergeRecordStartedEventHandler MailMergeRecordStarted

Event Data

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

Property Description
Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
Document Gets a merged document.
RecordDocument Gets a template document before a record is merged.
RecordIndex Gets an index of a record currently merged.

Remarks

The MailMergeRecordStarted event can be used to pre-process the merged section of a document that corresponds to a specified record.

Example

The code sample below shows how to handle the MailMergeRecordStarted and MailMergeRecordFinished events to insert additional content to the document:

View Example: Use DOCVARIABLE Fields

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
//...

private static void srv_MailMergeRecordStarted(object sender, MailMergeRecordStartedEventArgs e)
{
    DocumentPosition position = e.RecordDocument.Range.Start;
    DocumentRange _range =
        e.RecordDocument.InsertText(position, String.Format("Created on {0:G}\n\n", DateTime.Now));
    CharacterProperties cp = e.RecordDocument.BeginUpdateCharacters(_range);
    cp.FontSize = 8;
    cp.ForeColor = Color.Red;
    cp.Hidden = true;
    e.RecordDocument.EndUpdateCharacters(cp);
}

private static void srv_MailMergeRecordFinished(object sender, MailMergeRecordFinishedEventArgs e)
{
    e.RecordDocument.AppendDocumentContent("Docs\\bungalow.docx", DocumentFormat.OpenXml);
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the MailMergeRecordStarted event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also