# MailMerge: Merge CheckBoxes During the Merge Process

> TX Text Control MailMerge processes standard MergeFields automatically, but form checkboxes require additional handling. By iterating ApplicationFields in the DataRowMerged event and using the FormCheckBox adapter, developers can set checkbox state from boolean values in the data source.

- **Author:** Bjoern Meyer
- **Published:** 2015-01-12
- **Modified:** 2026-07-17
- **Description:** TX Text Control MailMerge processes standard MergeFields automatically, but form checkboxes require additional handling. By iterating ApplicationFields in the DataRowMerged event and using the FormCheckBox adapter, developers can set checkbox state from boolean values in the data source.
- **2 min read** (370 words)
- **Tags:**
  - Reporting
  - Tutorial
- **Web URL:** https://www.textcontrol.com/blog/2015/01/12/mailmerge-merge-checkboxes-during-the-merge-process/
- **LLMs URL:** https://www.textcontrol.com/blog/2015/01/12/mailmerge-merge-checkboxes-during-the-merge-process/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2015/01/12/mailmerge-merge-checkboxes-during-the-merge-process/llms-full.txt

---

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](https://s1-www.textcontrol.com/assets/dist/blog/2015/01/12/a/assets/results.webp "MailMerge: Merge CheckBoxes during the merge process")

You can [download](https://s1-www.textcontrol.com/assets/dist/blog/2015/01/12/a/assets/tx_checkbox_mailmerge.zip) the sample project for your own tests. At least a [trial version](https://www.textcontrol.com/product/tx-text-control-dotnet-winforms/download/) of TX Text Control .NET for Windows Forms is required.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Creating Your First ASP.NET Reporting Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-aspnet-reporting-application/llms.txt)
- [New Online Sample: Build your First Report](https://www.textcontrol.com/blog/2019/07/03/build-your-first-report/llms.txt)
- [Create your First Document with ReportingCloud](https://www.textcontrol.com/blog/2019/02/19/create-your-first-document-with-reportingcloud/llms.txt)
- [MailMerge: Starting Each Merge Block on a New Page](https://www.textcontrol.com/blog/2016/09/09/mailmerge-starting-each-merge-block-on-a-new-page/llms.txt)
- [Using MailMerge with JSON Data](https://www.textcontrol.com/blog/2015/08/04/using-mailmerge-with-json-data/llms.txt)
- [Merging Documents with RESTful Web API's](https://www.textcontrol.com/blog/2015/07/31/merging-documents-with-restful-web-apis/llms.txt)
- [Windows Forms: Printing Multiple Pages Per Sheet](https://www.textcontrol.com/blog/2015/07/24/windows-forms-printing-multiple-pages-per-sheet/llms.txt)
- [Inserting Watermark Images to All Pages Dynamically](https://www.textcontrol.com/blog/2015/07/17/inserting-watermark-images-to-all-pages-dynamically/llms.txt)
- [Reporting: Sorting Merge Block Rows by Column Name](https://www.textcontrol.com/blog/2015/07/15/reporting-sorting-merge-block-rows-by-column-name/llms.txt)
- [MailMerge with the Entity Framework Using Database First](https://www.textcontrol.com/blog/2015/06/24/mailmerge-with-the-entity-framework-using-database-first/llms.txt)
- [Checked and Unchecked Check Boxes with IF Fields](https://www.textcontrol.com/blog/2015/03/25/checked-and-unchecked-check-boxes-with-if-fields/llms.txt)
- [Reporting: Conditional Formatted Text Blocks](https://www.textcontrol.com/blog/2015/03/13/reporting-conditional-formatted-text-blocks/llms.txt)
- [Reporting Best Practices and How-To Guides](https://www.textcontrol.com/blog/2015/02/05/reporting-best-practices-and-how-to-guides/llms.txt)
- [MailMerge: Master Table and Client Tables](https://www.textcontrol.com/blog/2015/01/28/mailmerge-master-table-and-client-tables/llms.txt)
- [MailMerge: Formatting Numeric Strings in Merge Fields](https://www.textcontrol.com/blog/2015/01/22/mailmerge-formatting-numeric-strings-in-merge-fields/llms.txt)
- [MailMerge: Conditional INCLUDETEXT Fields](https://www.textcontrol.com/blog/2015/01/08/mailmerge-conditional-includetext-fields/llms.txt)
- [HTML5 Technical Considerations - The Concept Explained](https://www.textcontrol.com/blog/2014/10/16/html5-technical-considerations-the-concept-explained/llms.txt)
- [TX Text Control Web: Attaching Events to Ribbon Elements](https://www.textcontrol.com/blog/2014/10/07/tx-text-control-web-attaching-events-to-ribbon-elements/llms.txt)
- [TX Text Control Web: Customize the Ribbon Bar](https://www.textcontrol.com/blog/2014/10/03/tx-text-control-web-customize-the-ribbon-bar/llms.txt)
- [Text Control Web - Fundamental Concepts: The Data Source](https://www.textcontrol.com/blog/2014/10/02/text-control-web-fundamental-concepts-the-data-source/llms.txt)
- [Reporting: Removing Empty Table Rows](https://www.textcontrol.com/blog/2014/09/30/reporting-removing-empty-table-rows/llms.txt)
- [MS Word Content Controls Field Adapter Classes](https://www.textcontrol.com/blog/2014/08/05/ms-word-content-controls-field-adapter-classes/llms.txt)
- [Reporting: Merge Blocks and Structured Numbered Lists](https://www.textcontrol.com/blog/2014/07/29/reporting-merge-blocks-and-structured-numbered-lists/llms.txt)
- [Creating Avery Labels Using Text Control Reporting](https://www.textcontrol.com/blog/2014/07/22/creating-avery-labels-using-text-control-reporting/llms.txt)
- [New Online Samples for TX Text Control .NET Server](https://www.textcontrol.com/blog/2014/07/16/new-online-samples-for-tx-text-control-net-server-for-aspnet/llms.txt)
