public void FieldMerging(FieldMergingArgs args)
{
// Change the text of each field of the ContactDetails region individually.
if (args.TableName == "ContactDetails")
{
// Set the text of the field based off the field name.
if (args.FieldName == "Name")
args.Text = "(No details found)";
else if (args.FieldName == "Number")
args.Text = "(N/A)";
}
// Remove the entire table of the Suppliers region. Also check if the previous paragraph
// Before the table is a heading paragraph and if so remove that too.
if (args.TableName == "Suppliers")
{
Table table = (Table)args.Field.Start.GetAncestor(NodeType.Table);
// Check if the table has been removed from the document already.
if (table.ParentNode != null)
{
// Try to find the paragraph which precedes the table before the table is removed from the document.
if (table.PreviousSibling != null && table.PreviousSibling.NodeType == NodeType.Paragraph)
{
Paragraph previousPara = (Paragraph)table.PreviousSibling;
if (IsHeadingParagraph(previousPara))
previousPara.Remove();
}
table.Remove();
}
}
}