# Reporting: Custom Processing Using MailMerge Events

> The MailMerge component provides three events for custom document manipulation during the merge process: FieldMerged fires per field, DataRowMerged fires per completed row, and BlockRowMerged fires per merge block row. Each event exposes content as a byte array for editing.

- **Author:** Bjoern Meyer
- **Published:** 2014-05-07
- **Modified:** 2026-07-17
- **Description:** The MailMerge component provides three events for custom document manipulation during the merge process: FieldMerged fires per field, DataRowMerged fires per completed row, and BlockRowMerged fires per merge block row. Each event exposes content as a byte array for editing.
- **3 min read** (536 words)
- **Tags:**
  - Reporting
  - Tutorial
- **Web URL:** https://www.textcontrol.com/blog/2014/05/07/reporting-custom-processing-using-mailmerge-events/
- **LLMs URL:** https://www.textcontrol.com/blog/2014/05/07/reporting-custom-processing-using-mailmerge-events/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2014/05/07/reporting-custom-processing-using-mailmerge-events/llms-full.txt
- **GitHub Repository:** https://github.com/TextControl/TextControl.MailMerge.CustomProcessingWithEvents

---

Text Control's Reporting engine [MailMerge](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.documentserver.mailmerge.class.htm) is based on TX Text Control .NET and encapsulates the required mail merge features such as looping through merge fields, repeating blocks and populating fields with data. It allows you to create professional reports without writing a single line of code.

The component **MailMerge** is connected to an instance of TX Text Control that is visible ([TXTextControl.TextControl](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.documentserver.mailmerge.class.htm)) or not ([TXTextControl.ServerTextControl](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.servertextcontrol.class.htm)).

Learn more about reporting and how to create your first Text Control Reporting application here:

[Text Control Reporting](https://www.textcontrol.com/technology/reporting/)

A huge advantage is the flexibility you gain when using Text Control Reporting compared to banded reporting tools. Thanks to the complete and powerful API, you can post-process the created documents programmatically or modify them in the editor TX Text Control manually.

During the merge process, there are 3 events that can be used to manipulate the document with the TX Text Control API:

1. **[FieldMerged](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.documentserver.mailmerge.fieldmerged.event.htm)**  
    This event is raised for each merged field and can be used to [inject formatted text](https://www.textcontrol.com/blog/2013/07/30/reporting-merge-formatted-text-into-mergefields-using-html/llms-full.txt) into merge fields.
2. **[DataRowMerged](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.documentserver.mailmerge.datarowmerged.event.htm)**  
    This event is raised for each completed data row of the most outer data source object or table can be used to manipulate this complete record.
3. **[BlockRowMerged](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.documentserver.mailmerge.blockrowmerged.event.htm)**  
    This event is raised for each completed row of a merge block and can be used to manipulate this complete row.

All of these events return the complete content as a byte array in the internal TX Text Control format. This can be a single word or character, a table row or a complete document. This byte array can be loaded into a non-UI ServerTextControl, post-processed and loaded back into the merge document.

The following sample merges a template with an address table. For each data row, the contained tables are resized to apply AutoFit settings to a table.

![Custom processing using MailMerge events](https://s1-www.textcontrol.com/assets/dist/blog/2014/05/07/a/assets/tx_template.webp "Custom processing using MailMerge events")```
private void mailMerge1_DataRowMerged(object sender,
    TXTextControl.DocumentServer.MailMerge.DataRowMergedEventArgs e)
{
    using (TXTextControl.ServerTextControl tx =
        new TXTextControl.ServerTextControl())
    {
        tx.Create();

        tx.Load(e.MergedRow,
            TXTextControl.BinaryStreamType.InternalUnicodeFormat);

        foreach (Table table in tx.Tables)
        {
            table.AutoSize(tx);
        }

        byte[] data;

        tx.Save(out data, BinaryStreamType.InternalUnicodeFormat);
        e.MergedRow = data;
    }
}
```

After the merge, the table on each page has been adjusted to fit the cell content:

![Custom processing using MailMerge events](https://s1-www.textcontrol.com/assets/dist/blog/2014/05/07/a/assets/tx_template_results.webp "Custom processing using MailMerge events")Download the sample from GitHub and test it on your own.

Summary: Text Control Reporting gives you a very powerful way to merge MS Word compatible templates automatically, but at the same time a flexible API to modify the merged document, if necessary.

---

## 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: Merge CheckBoxes During the Merge Process](https://www.textcontrol.com/blog/2015/01/12/mailmerge-merge-checkboxes-during-the-merge-process/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)
