Back to Devexpress

RichEditControl.MailMergeRecordStarted Event

windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-979675b2.md

latest4.5 KB
Original Source

RichEditControl.MailMergeRecordStarted Event

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

Namespace : DevExpress.XtraRichEdit

Assembly : DevExpress.XtraRichEdit.v25.2.dll

NuGet Package : DevExpress.Win.RichEdit

Declaration

csharp
public event MailMergeRecordStartedEventHandler MailMergeRecordStarted
vb
Public Event MailMergeRecordStarted As MailMergeRecordStartedEventHandler

Event Data

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

PropertyDescription
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
DocumentGets a merged document.
MailMergeRegionInfoObtains information on the currently merged region.
RecordDocumentGets a template document before a record is merged.
RecordIndexGets 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 particular record. The following code snippet demonstrates how to insert a creation time mark for each merged record in the resulting document.

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

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

private static void RichEditControl_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 RichEditControl_MailMergeRecordFinished(object sender, MailMergeRecordFinishedEventArgs e)
{
    e.RecordDocument.AppendDocumentContent("Docs\\bungalow.docx", DocumentFormat.Docx);
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
'...

Private Shared Sub RichEditControl_MailMergeRecordStarted(ByVal sender As Object, ByVal e As MailMergeRecordStartedEventArgs)
    Dim position As DocumentPosition = e.RecordDocument.Range.Start
    Dim _range As DocumentRange = e.RecordDocument.InsertText(position, String.Format("Created on {0:G}" & vbLf & vbLf, DateTime.Now))
    Dim cp As CharacterProperties = e.RecordDocument.BeginUpdateCharacters(_range)
    cp.FontSize = 8
    cp.ForeColor = Color.Red
    cp.Hidden = True
    e.RecordDocument.EndUpdateCharacters(cp)
End Sub

Private Shared Sub RichEditControl_MailMergeRecordFinished(ByVal sender As Object, ByVal e As MailMergeRecordFinishedEventArgs)
    e.RecordDocument.AppendDocumentContent("Docs\bungalow.docx", DocumentFormat.Docx)
End Sub

See Also

RichEditControl Class

RichEditControl Members

DevExpress.XtraRichEdit Namespace