The TXTextControl.DocumentServer.MailMerge.FieldMerged event TX Text Control .NET for Windows Forms
DocumentServer Namespace
MailMerge Class
FieldMerged Event
Occurs when a field has been merged.
returns useful information and options to manipulate the merged content in the TXTextControl.DocumentServer.MailMerge.FieldMergedEventArgs class TX Text Control .NET for Windows Forms
DocumentServer Namespace
MailMerge.FieldMergedEventArgs Class
The FieldMergedEventArgs class provides data for the FieldMerged event.
.

Since version X14 (24.0), the TXTextControl.DocumentServer.MailMerge.FieldMergedEventArgs.TableCell property TX Text Control .NET for Windows Forms
DocumentServer Namespace
MailMerge.FieldMergedEventArgs Class
TableCell Property
If the merge field is inside of a table, this property returns the containing table cell as a TXTextControl.TableCell instance or null otherwise.
returns a TXTextControl.TableCell class TX Text Control .NET for Windows Forms
TXTextControl Namespace
TableCell Class
An instance of the TableCell class represents a single cell of a table in a Text Control document.
in case the merge field is positioned inside a table. This can be used to manipulate the table cell based on merged values.

Consider the following data structure and instance that is used to merge a template:

public class Report
{
public Row[] Rows { get; set; }
}
public class Row
{
public int Value { get; set; }
public string Name { get; set; }
}
Report report = new Report()
{
Rows = new Row[] {
new Row() { Name = "Row0", Value = 10 },
new Row() { Name = "Row1", Value = 100 },
new Row() { Name = "Row2", Value = 200 },
new Row() { Name = "Row3", Value = 300 },
new Row() { Name = "Row4", Value = 400 },
new Row() { Name = "Row5", Value = 500 },
new Row() { Name = "Row6", Value = 600 },
new Row() { Name = "Row7", Value = 700 },
}
};
reports = new List<Report>() { report };
view raw tx.cs hosted with ❤ by GitHub

The following code creates a new instance of the reporting engine TXTextControl.DocumentServer.MailMerge class TX Text Control .NET for Windows Forms
DocumentServer Namespace
MailMerge Class
The MailMerge class is a .NET component that can be used to effortlessly merge template documents with database content in .NET projects, such as ASP.NET web applications, web services or Windows services.
, attaches the FieldMerged event and calls the TXTextControl.DocumentServer.MailMerge.MergeObjects method TX Text Control .NET for Windows Forms
DocumentServer Namespace
MailMerge Class
MergeObjects Method
Merges a collection of type System.Collections.IEnumerable containing objects of any type or instances of type System.Collections.Generic.Dictionary with string keys into the loaded document template.
to merge a template with the created data object.

using (MailMerge mailMerge = new MailMerge())
{
mailMerge.TextComponent = textControl1;
mailMerge.FieldMerged += mailMerge_FieldMerged;
mailMerge.MergeObjects(reports);
}
view raw tx.cs hosted with ❤ by GitHub

In the FieldMerged event, the field value is parsed and mapped to a color based on the value range. Accordingly, the background color of the outer table cell is highlighted.

private void mailMerge_FieldMerged(object sender, MailMerge.FieldMergedEventArgs e)
{
if (e.TableCell == null)
return;
if (e.MailMergeFieldAdapter.TypeName == MergeField.TYPE_NAME)
{
MergeField mergeField = e.MailMergeFieldAdapter as MergeField;
Color cellColor;
int value;
if (int.TryParse(mergeField.Text, out value) == true)
{
if (value >= 700)
cellColor = Color.Red;
else if (value >= 600)
cellColor = Color.Orange;
else if (value >= 500)
cellColor = Color.Yellow;
else if (value >= 400)
cellColor = Color.Green;
else if (value >= 300)
cellColor = Color.Blue;
else if (value >= 200)
cellColor = Color.Indigo;
else if (value >= 100)
cellColor = Color.Violet;
else
cellColor = e.TableCell.CellFormat.BackColor;
e.TableCell.CellFormat.BackColor = cellColor;
}
}
}
view raw tx.cs hosted with ❤ by GitHub

The following screenshot shows the results of this merge process:

Colored table cells

This is just one of many ideas what to do with the flexible reporting framework MailMerge to customize the merging process.