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:

MailMerge: Merge CheckBoxes during the merge process

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.