Flow Type Layout Reporting Series: Master-detail Relationship Blocks
A master-detail relationship is a 1:n (one-to-many) type relationship. A typical example for such a relationship is a purchase order and a set of items that belongs to each purchase order. This allows you to create complex nested reports in a very easy way. TX Text Control's repeating blocks can be nested in unlimited levels. Those nested blocks can be inserted in the same way like usual merge blocks. Each block has an unique name which should match the name of a DataTable in the merge data.…


A master-detail relationship is a 1:n (one-to-many) type relationship. A typical example for such a relationship is a purchase order and a set of items that belongs to each purchase order. This allows you to create complex nested reports in a very easy way.
TX Text Control's repeating blocks can be nested in unlimited levels. Those nested blocks can be inserted in the same way like usual merge blocks.
Each block has an unique name which should match the name of a DataTable in the merge data. If nested blocks with an existing DataRelation are recognized, they are combined automatically. The following screenshot shows the concept of nested blocks and the data relations:

The range from the green start bookmark to the green end bookmark is the outer block representing article groups. The inner block is marked with blue markers.
Marker colors are for visualization purposes only. In TX Text Control, all markers are gray.
Looking at the merged results show that the articles are mapped automatically:

The Merge Data Structure
The block data consists of two tables with an unique relationship (article_group_id):

Inserting the Nested Blocks
-
In TX Text Control Words, insert a table as shown below with a merge field in a cell from the outer data table.
-
Select the table and 2 blank lines under the table and choose Insert Merge Block from the Merge Block ribbon group.
In the opened dialog box, type in the name of the outer DataTable and confirm with OK.
-
Insert another table below the existing table and add fields from the inner data table. Select the whole table row in order to insert another block called Article.
The following code shows how to build the data, the data relationships and how to merge these blocks using TX Text Control's Reporting classes:
DataSet dsBlockData = new DataSet();
// article group
DataTable dtGroup = new DataTable("Group");
dtGroup.Columns.Add("article_group_id");
dtGroup.Columns.Add("article_group_name");
dtGroup.Rows.Add(new object[] { 1, "Vegetables" });
dtGroup.Rows.Add(new object[] { 2, "Fruits" });
// article
DataTable dtArticle = new DataTable("Article");
dtArticle.Columns.Add("article_group_id");
dtArticle.Columns.Add("article_name");
dtArticle.Columns.Add("article_description");
dtArticle.Columns.Add("article_price");
dtArticle.Rows.Add(new object[] { 1, "Asparagus",
"Asparagus officinalis is a spring vegetable.", "110" });
dtArticle.Rows.Add(new object[] { 1, "Potato",
"The potato is a starchy crop of the Solanaceae family.", "220" });
dtArticle.Rows.Add(new object[] { 1, "Carrot",
"The carrot is a root vegetable, usually orange in colour.", "330" });
dtArticle.Rows.Add(new object[] { 2, "Apple",
"The apple is the pomaceous fruit of the apple tree.", "440" });
dtArticle.Rows.Add(new object[] { 2, "Strawberry",
"The strawberry is a hybrid species.", "550" });
dsBlockData.Tables.Add(dtGroup);
dsBlockData.Tables.Add(dtArticle);
DataRelation drGroupArticle = new DataRelation("GroupArticle",
dsBlockData.Tables["Group"].Columns["article_group_id"],
dsBlockData.Tables["Article"].Columns["article_group_id"]);
dsBlockData.Relations.Add(drGroupArticle);
mailMerge1.MergeBlocks(dsBlockData);
mailMerge1.Merge(null, true);
Related Posts
Windows FormsGetting StartedTutorial
Windows Forms Tutorial: Create Your First Windows Forms C# Application
This tutorial shows how to create your first Windows Forms application with C# using TX Text Control .NET for Windows Forms in Visual Studio 2022.
How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#
Mail merge is the process of merging data, such as Json or IEnumerable objects, into a template document, such as a DOC or DOCX file. This tutorial is a walkthrough of the steps necessary to…
Creating an Angular Document Editor Application with a Node.js WebSocket Server
This tutorial shows how to create an Angular application that uses the Document Editor with a Node.js WebSocket server.
Adding SVG Watermarks to Documents
This article shows how to add SVG images to document section headers that repeat automatically on each page. This watermark will be inserted vertically and horizontally centered on each section page.
Using MailMerge in ASP.NET Core 6 Web Applications
This article shows how to use the TX Text Control ASP.NET MailMerge class to merge templates with JSON data within a .NET 6 application in Visual Studio 2022.