Products Technologies Demo Docs Blog Support Company

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.

X19 Sneak Peek: Manipulating MergeBlockInfo Objects

Typically, a merge block is used to repeat content such as table rows. The MailMerge class is using the hierarchical data to repeat the content and to populate fields with data in that block. This merge block provides 3 different options that can be controlled:

  • Filters
  • Sorting
  • Rendering conditions

Those options can be defined through a dialog box or when adding a merge block programmatically through the MergeBlockInfo class.

MergeBlockInfo Class

An extension in version X19 provides a way to create a MergeBlockInfo instance based on an existing merge block SubTextPart.

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:

Merge Blocks

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):

Merge Blocks

Stay tuned for more improvements and new features of TX Text Control X19!

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

ASP.NETWindows FormsWPF

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…


ASP.NETWindows FormsWPF

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…


ActiveXASP.NETWindows Forms

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…


ASP.NETWindows FormsWPF

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…


ASP.NETWindows FormsWPF

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…