X19 Sneak Peek: Manipulating MergeBlockInfo Objects
TX Text Control X19 provides the possibility to retrieve and manipulate information of an existing MailMerge merge block. This enables the editing of filters and sorting instructions programmatically.

Typically, a merge block is used to repeat content such as table rows. The Mail
- Filters
- Sorting
- Rendering conditions
Those options can be defined through a dialog box or when adding a merge block programmatically through the Merge
MergeBlockInfo Class
An extension in version X19 provides a way to create a MergeBlockInfo instance based on an existing merge block Sub
Consider the following JSON string as the data source:
[
{
"items": [
{
"id": 1,
"status": "",
"calibrated": 1521135120000,
"location": {
"latitude": -117.125,
"longitude": 31.125
}
},
{
"id": 2,
"status": "offline",
"calibrated": 1521638100000,
"location": {
"latitude": -113.325,
"longitude": 33.325
}
},
{
"id": 3,
"status": "error",
"calibrated": 1522291320000,
"location": {
"latitude": -111.625,
"longitude": 35.625
}
}
]
}
]
The following screenshot shows a nested merge block including the blocks items and location:
The inner merge block location should be only rendered, if the id of the parent block (items) is > 1.
Manipulate MergeBlock Conditions
The following code shows how to retrieve a SubTextPart and to create a new MergeBlockInfo object to apply the required merge condition:
// find the SubTextPart
SubTextPart mergeBlock = textControl1.SubTextParts.GetItem("txmb_location");
// create a new MergeBlockInfo object from SubTextPart
TXTextControl.DocumentServer.DataSources.MergeBlockInfo mbInfo =
new TXTextControl.DocumentServer.DataSources.MergeBlockInfo(mergeBlock);
// add a condition:
// render block, if "id" from parent is greater than 1
mbInfo.BlockMergingCondition.Add(
new TXTextControl.DocumentServer.DataShaping.FilterInstruction(
"id",
TXTextControl.DocumentServer.DataShaping.RelationalOperator.GreaterThan,
1));
// apply conditions
mbInfo.Apply();
When the template is merged using MailMerge, you can see that the first inner merge block is not merged while the other 2 blocks are merged as they match the condition (id > 1):
Stay tuned for more improvements and new features of TX Text Control X19!
Jump to the other posts in this series:
- X19 Sneak Peek: Table of Contents
- X19 Sneak Peek: Embedded Files in Adobe PDF Documents
- X19 Sneak Peek: Integrated Barcode Support
- X19 Sneak Peek: Processing AcroForm Fields in Adobe PDF Documents
- X19 Sneak Peek: Storing Document Revisions in PDF/A-3b
- X19 Sneak Peek: Validating ZUGFeRD / Factur-X Invoices with TX Text Control
- X19 Sneak Peek: Changes for Keyboard Layout and Spell Checking
- X19 Sneak Peek: Manipulating MergeBlockInfo Objects
Related Posts
TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version
TX Text Control 33.0 Service Pack 3 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…
TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version
TX Text Control 33.0 Service Pack 2 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…
Service Pack Releases: What's New in TX Text Control 33.0 SP1 and 32.0 SP5
TX Text Control 33.0 Service Pack 1 and TX Text Control 32.0 Service Pack 5 have been released, providing important updates and bug fixes across platforms. These service packs improve the…
The Wait is Over: TX Text Control for Linux is Officially Here
We are very excited to announce the release of TX Text Control 33.0 which includes the long awaited Linux version of TX Text Control. This version allows you to integrate TX Text Control into your…
Full .NET 9 Support in Text Control .NET Components for ASP.NET Core,…
.NET 9 will be launched tomorrow, November 12, at the .NET Conf 2024 with updates to cloud capabilities, security, and performance. TX Text Control .NET components are fully compatible with .NET 9…