MailMerge: Merge CheckBoxes During the Merge Process
TX Text Control's reporting engine MailMerge supports commonly used fields compatible with the mail merge functionality of MS Word including MergeFields, IncludeText fields and Date fields. Besides those standard fields, the DocumentServer namespace contains field adapter for MS Word form fields, such as checkboxes, drop-down boxes and form text fields, and content control fields. MergeFields that are merged automatically during the MailMerge merge process can be also combined with form…

TX Text Control's reporting engine MailMerge supports commonly used fields compatible with the mail merge functionality of MS Word including MergeFields, IncludeText fields and Date fields. Besides those standard fields, the DocumentServer namespace contains field adapter for MS Word form fields, such as checkboxes, drop-down boxes and form text fields, and content control fields.
MergeFields that are merged automatically during the MailMerge merge process can be also combined with form fields such as checkboxes. The following method loops through the ApplicationFields in order to merge included check boxes:
private byte[] processFormCheckBoxFields(byte[] document, DataRow dataRow)
{
// load merged row into a temporary ServerTextControl
using (TXTextControl.ServerTextControl tx =
new TXTextControl.ServerTextControl())
{
tx.Create();
tx.Load(document, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
// loop through all text parts
foreach (IFormattedText textPart in tx.TextParts)
{
// loop through all form checkbox fields
foreach (ApplicationField appField in textPart.ApplicationFields)
{
if (appField.TypeName == "FORMCHECKBOX")
{
FormCheckBox checkbox = new FormCheckBox(appField);
// set the value
if(dataRow.Table.Columns[checkbox.Name] != null)
checkbox.Checked =
Convert.ToBoolean(dataRow[checkbox.Name]);
}
}
}
byte[] data;
tx.Save(out data, BinaryStreamType.InternalUnicodeFormat);
return data;
}
}
The MailMerge class merges only merge fields as part of the merge process. After the merging process, included form fields are still part of the document. In the DataRowMerged event, the merged document is simply passed to the processFormCheckBoxFields method to process the form fields. The resulting document is returned in the MergedRow property:
private void mailMerge1_DataRowMerged(object sender,
TXTextControl.DocumentServer.MailMerge.DataRowMergedEventArgs e)
{
// return the modified merged row document
e.MergedRow = processFormCheckBoxFields(e.MergedRow,
ds.Tables[0].Rows[e.DataRowNumber]);
}
The value for the check boxes are simple boolean fields in the data source:
<report>
<entry>
<name>Petersen</name>
<firstname>Paul</firstname>
<check1>true</check1>
<check2>false</check2>
</entry>
<entry>
<name>Morrison</name>
<firstname>Jamie</firstname>
<check1>true</check1>
<check2>true</check2>
</entry>
<entry>
<name>Woldorf</name>
<firstname>Walter</firstname>
<check1>false</check1>
<check2>false</check2>
</entry>
<entry>
<name>Jackson</name>
<firstname>Peter</firstname>
<check1>true</check1>
<check2>true</check2>
</entry>
</report>
The following screenshot shows the resulting document of the sample project:

You can download the sample project for your own tests. At least a trial version of TX Text Control .NET for Windows Forms is required.
Reporting
The Text Control Reporting Framework combines powerful reporting features with an easy-to-use, MS Word compatible word processor. Users can create documents and templates using ordinary Microsoft Word skills. The Reporting Framework is included in all .NET based TX Text Control products including ASP.NET, Windows Forms and WPF.
Related Posts
Creating Your First ASP.NET Reporting Application
This tutorial shows how to use the MailMerge component in an ASP.NET Web application to merge a template with data to create an Adobe PDF document.
New Online Sample: Build your First Report
We published a new online demo that shows how to create a report including preparing data, creating a template to merging them together.
ReportingDocumentationReportingCloud
Create your First Document with ReportingCloud
As part of our new ReportingCloud documentation, we published a guided tutorial that shows how to create a document without programming.
MailMerge: Starting Each Merge Block on a New Page
A merge block is repeated based on the number of matching data rows in the hierarchical data object. The complete merge block is cloned and inserted under the original location in the template.…
Using MailMerge with JSON Data
In the last article, we explained how to create an ASP.NET Web API to merge templates with JSON data in the payload body of an HTTP request. The focus of this article was on the Web API and…