Adding Sorting and Filter Instructions to Existing MergeBlocks
Merge blocks can be filtered and sorted with linked instructions that help to shape the used data in each merge block. This article shows how to add sorting and filter instructions to existing merge blocks.

Merge blocks can be filtered and sorted with linked instructions that help to shape the used data in each merge block. This article shows how to add sorting and filter instructions to existing merge blocks.
These instructions can be added using the out-of-the-box dialog boxes. Consider the following merge block:
Using the Dialog
A dialog box can be used to add filters and sorting instructions:
After a filter has been added using the dialog, only data rows with a LineTotal value larger than 1000 are visible:
Apply Instructions Programmatically
In order to apply these instructions programmatically, the Merge
// check if there is a SubTextPart at the
// current input position
if (textControl1.SubTextParts.GetItem() == null)
return;
// retrieve current SubTextPart
SubTextPart stpMergeBlock = textControl1.SubTextParts.GetItem();
// check if SubTextPart is a MergeBlock
if (TXTextControl.DocumentServer.DataSources.DataSourceManager.IsMergeBlock(
textControl1.SubTextParts.GetItem()) == true) {
// create a MergeBlockInfo object from SubTextPart
TXTextControl.DocumentServer.DataSources.MergeBlockInfo mbInfo =
new TXTextControl.DocumentServer.DataSources.MergeBlockInfo(stpMergeBlock);
// add a filter
mbInfo.Filters.Add(
new TXTextControl.DocumentServer.DataShaping.FilterInstruction(
"Price",
TXTextControl.DocumentServer.DataShaping.RelationalOperator.GreaterThan,
500));
mbInfo.SortingInstructions.Add(
new TXTextControl.DocumentServer.DataShaping.SortingInstruction(
"Price",
TXTextControl.DocumentServer.DataShaping.SortOrder.Ascending));
// important: apply the settings
mbInfo.Apply();
At the end, it is very important to call the Apply method that stores the meta data (filters, sorting instructions and the block merging condition) in the SubTextPart which represents the merge block.
Also See
This post references the following in the documentation:
- TXText
Control. Document Server. Data Shaping. Filter Instruction Class - TXText
Control. Document Server. Data Shaping. Sorting Instruction Class - TXText
Control. Document Server. Data Sources. Data Source Manager Class - TXText
Control. Document Server. Data Sources. Merge Block Info Class
Related Posts
MailMerge: Merging Hyperlinks using the FieldMerged Event
The MailMerge class is used to merge data into merge fields, image placeholders, barcodes and other reporting elements. With the help of the flexible FieldMerged event, additional elements can be…
Mail Merge MS Word Office Open XML (DOCX) Templates in C#
TX Text Control's MailMerge engine allows you to perform MS Word compatible mail merge processes in .NET based applications. This article gives an overview of the basic functionality and shows how…
MailMerge: Field Mapping and Handling of Unmerged Fields
Text Control's MailMerge API maps merge fields in templates with columns in supported data sources. This article explains the structure and how to handle unmerged fields.
MailMerge: Data Structures Explained with a Sample Template and JSON Data
The MailMerge class is used to merge JSON data into templates including merge fields and repeating merge blocks. This article gives an overview of the data structure based on a sample template…
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.