# X14 Preview: Build Your Own Template Designer with the New DataSourceManager Class

> TX Text Control X14 adds the DataSourceManager class for building custom template designers. It loads data from DataSet, JSON, XML, or .NET objects and exposes events like PossibleMergeFieldColumnsChanged to update available merge fields and blocks as the master table changes.

- **Author:** Bjoern Meyer
- **Published:** 2016-11-15
- **Modified:** 2026-03-05
- **Description:** TX Text Control X14 adds the DataSourceManager class for building custom template designers. It loads data from DataSet, JSON, XML, or .NET objects and exposes events like PossibleMergeFieldColumnsChanged to update available merge fields and blocks as the master table changes.
- **4 min read** (763 words)
- **Tags:**
  - ASP.NET
  - Release
  - Reporting
  - Windows Forms
  - WPF
- **Web URL:** https://www.textcontrol.com/blog/2016/11/15/x14-preview-build-your-own-template-designer-with-the-new-datasourcemanager-class/
- **LLMs URL:** https://www.textcontrol.com/blog/2016/11/15/x14-preview-build-your-own-template-designer-with-the-new-datasourcemanager-class/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2016/11/15/x14-preview-build-your-own-template-designer-with-the-new-datasourcemanager-class/llms-full.txt

---

Version X14 comes with pre-configured [ribbon tabs](https://www.textcontrol.com/blog/2016/11/03/sneak-peek-windows-forms-ribbon-bar-visual-studio-design-time-support/llms-full.txt) for all typical tasks of TX Text Control. One of these ribbon tabs is the *RibbonReportingTab*. It provides a fully featured ribbon tab to create MS Word compatible templates for the Text Control Reporting Framework. Data sources such as MS SQL, ODBC and ADO.NET can be loaded, the master table can be set and available merge blocks and merge fields can be inserted.

![Build your own template designer with the new DataSourceManager class](https://s1-www.textcontrol.com/assets/dist/blog/2016/11/15/a/assets/ribbon_reporting.webp "Build your own template designer with the new DataSourceManager class")This new ribbon tab is based on the new public class *DataSourceManager* that encapsulates the complete handling, logic and ready-to-use dialog boxes for the reporting template creation task. The following diagram shows the new classes in detail:

![DataSourceManager class](https://s1-www.textcontrol.com/assets/dist/blog/2016/11/15/a/assets/datasourcemanager_diagram_2.webp "DataSourceManager class")Essentially, the DataSourceManager provides all information required to create a fully-featured template designer. Like with [MailMerge](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.documentserver.mailmerge.class.htm), a data source can be loaded from a DataSet, DataTable, Json, an object or XML. In this sample, a simple .NET class is used as a data source:

```
public class Order
{
    public int OrderID { get; set; }
    public Customer Customer { get; set; }
    public List<OrderItem> OrderItems { get; set; }
}

public class OrderItem
{
    public Product Product { get; set; }
    public int Quantity { get; set; }
}

public class Product
{
    public string Name { get; set; }
}

public class Customer
{
    public string Name { get; set; }
}
```

This sample shows the typical work-flow of a template designer:

![DataSourceManager class](https://s1-www.textcontrol.com/assets/dist/blog/2016/11/15/a/assets/sample_screenshot.webp "DataSourceManager class")After clicking the button *Load Data Source*, a new instance of the *DataSourceManager* is created and the data object is loaded.

```
// create new merge data
Order order = new Order()
{
    OrderID = 123,
    Customer = new Customer()
    {
        Name = "Peter Welch"
    },
    OrderItems = new List<OrderItem>()
    {
        new OrderItem() {
            Product = new Product() {
                Name = "Product A" },
            Quantity = 2 }
    }
};

// create a new instance of the DataSourceManager
dsManager = new DataSourceManager();

// load the data source
dsManager.LoadSingleObject(order);
```

When a data source is loaded into the *DataSourceManager*, a ComboBox is bound to all available *DataTables*. Additionally, the events *PossibleMergeFieldColumnsChanged* and *PossibleMergeBlockTablesChanged* are attached to update two other ComboBoxes that list the available merge fields and merge blocks.

```
// attach events to monitor available merge fields and merge blocks
dsManager.PossibleMergeFieldColumnsChanged += 
    DsManager_PossibleMergeFieldColumnsChanged;
dsManager.PossibleMergeBlockTablesChanged += 
    DsManager_PossibleMergeBlockTablesChanged;

// attach the available tables to the combobox
cbMasterTable.DataSource = 
    dsManager.DataTables.ToList<DataTableInfo>();
cbMasterTable.DisplayMember = "TableName";
```

When the internal master table is changed, the ComboBoxes are updated with the available fields and blocks:

```
private void DsManager_PossibleMergeBlockTablesChanged(object sender, EventArgs e)
{
    // attach the available merge blocks to the combobox
    cbMergeBlocks.Text = "";
    cbMergeBlocks.DataSource =
        dsManager.PossibleMergeBlockTables.ToList<DataTableInfo>();
    cbMergeBlocks.DisplayMember = "TableName";
}

private void DsManager_PossibleMergeFieldColumnsChanged(object sender, EventArgs e)
{
    // attach the available merge fields to the combobox
    cbMergeFields.Text = "";
    cbMergeFields.DataSource =
        dsManager.PossibleMergeFieldColumns.ToList<DataColumnInfo>();
    cbMergeFields.DisplayMember = "ColumnName";
}
```

If the input position is inside a merge block, only the available fields and blocks inside this block should be available. Therefore, the [SubTextPartEntered](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.textcontrol.subtextpartentered.event.htm) event is used to define a new internal master table. The ComboBoxes are updated automatically through the attached events.

```
private void textControl1_SubTextPartEntered(object sender, 
                                             TXTextControl.SubTextPartEventArgs e)
{
    // is the SubTextPart a valid merge block?
    if (DataSourceManager.IsMergeBlock(e.SubTextPart))
    {
        // set the merge block as the new internal master table
        if(dsManager.DataTables.Contains(e.SubTextPart.Name.Remove(0, 5)))
            dsManager.MasterDataTableInfo = 
            dsManager.DataTables[e.SubTextPart.Name.Remove(0,5)];
    }
}

private void textControl1_SubTextPartLeft(object sender, 
                                          TXTextControl.SubTextPartEventArgs e)
{
    // set the master table back to the originally selected table
    dsManager.MasterDataTableInfo = cbMasterTable.SelectedItem as DataTableInfo;
}
```

When clicking the *Preview* button, the new *Merge* method of the *DataSourceManager* is used to merge the data into the template:

```
private void cbPreview_CheckedChanged(object sender, EventArgs e)
{
    // preview the mail merge document
    if (cbPreview.Checked)
    {
        // save the template 
        gbMergeElements.Enabled = false;
        textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect;
        textControl1.Save(out previewTemplate, 
            TXTextControl.BinaryStreamType.InternalUnicodeFormat);

        // merge the template using the DataSourceManager
        IList<byte[]> documents = 
            dsManager.Merge(previewTemplate, textControl1);

        // load the merged document into TextControl
        textControl1.Load(documents[0], 
            TXTextControl.BinaryStreamType.InternalUnicodeFormat);
    }
    else
    {
        // load back the stored template
        gbMergeElements.Enabled = true;
        textControl1.EditMode = TXTextControl.EditMode.Edit;
        textControl1.Load(previewTemplate, 
            TXTextControl.BinaryStreamType.InternalUnicodeFormat);
    }
}
```

Using the *DataSourceManager*, the complete task of designing mail merge templates can be realized. The class encapsulates the work-flow, logic and all required dialog boxes and preview functionality.

Stay tuned for more details about X14!

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [TX Text Control 32.0 Has Been Released](https://www.textcontrol.com/blog/2023/09/13/tx-text-control-320-has-been-released/llms.txt)
- [TX Text Control 31.0 and TX Spell .NET 10.0 Have Been Released](https://www.textcontrol.com/blog/2022/09/07/tx-text-control-31-released/llms.txt)
- [TX Text Control 30.0 and TX Spell .NET 9.0 Have Been Released](https://www.textcontrol.com/blog/2021/11/29/tx-text-control-30-released/llms.txt)
- [TX Text Control X19 and TX Spell 8.0 Have Been Released](https://www.textcontrol.com/blog/2020/12/02/tx-text-control-x19-released/llms.txt)
- [TX Text Control X18 has been Released](https://www.textcontrol.com/blog/2020/03/16/tx-text-control-x18-released/llms.txt)
- [TX Text Control X17 has been Released](https://www.textcontrol.com/blog/2019/05/28/tx-text-control-x17-released/llms.txt)
- [Text Control Roadmap 2019: High DPI Support, Forms, Node.js and Angular](https://www.textcontrol.com/blog/2019/03/12/text-control-roadmap-2019/llms.txt)
- [TX Text Control X16 and TX Barcode .NET 5.0 Released](https://www.textcontrol.com/blog/2018/11/14/tx-text-control-x16-and-tx-barcode-net-50-released/llms.txt)
- [Sneak Peek X16: Filter and Sort MergeBlock Rows](https://www.textcontrol.com/blog/2018/04/26/sneak-peek-x16-filter-and-sort-mergeblock-rows/llms.txt)
- [X15: Merging Data into Chart Objects](https://www.textcontrol.com/blog/2018/01/05/merging-data-into-charts/llms.txt)
- [TX Text Control X15 and TX Spell .NET 7.0 Released](https://www.textcontrol.com/blog/2017/12/13/tx-text-control-x15-and-tx-spell-net-70-released/llms.txt)
- [Sneak Peek X15: MS Word Compatible Document Protection and Editable Regions](https://www.textcontrol.com/blog/2017/11/16/ms-word-compatible-editable-regions/llms.txt)
- [TX Spell .NET 11.0 SP1 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2026/04/08/tx-spell-net-11-0-sp1-is-now-available/llms.txt)
- [TX Text Control 34.0 SP2 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2026/02/18/tx-text-control-34-0-sp2-is-now-available/llms.txt)
- [TX Text Control 34.0 SP1 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2025/12/03/tx-text-control-34-0-sp1-is-now-available/llms.txt)
- [Introducing TX Text Control 34.0: Your Next Leap in Document Processing](https://www.textcontrol.com/blog/2025/11/10/introducing-tx-text-control-34-0-your-next-leap-in-document-processing/llms.txt)
- [Sneak Peek: TX Text Control 34.0 Coming November 2025](https://www.textcontrol.com/blog/2025/10/02/sneak-peek-tx-text-control-34-0-coming-november-2025/llms.txt)
- [TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2025/08/14/tx-text-control-33-0-sp3-is-now-available/llms.txt)
- [TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2025/06/18/tx-text-control-33-0-sp2-is-now-available/llms.txt)
- [Service Pack Releases: What's New in TX Text Control 33.0 SP1 and 32.0 SP5](https://www.textcontrol.com/blog/2025/05/07/service-pack-releases-whats-new-in-tx-text-control-33-0-sp1-and-32-0-sp5/llms.txt)
- [The Wait is Over: TX Text Control for Linux is Officially Here](https://www.textcontrol.com/blog/2025/03/12/the-wait-is-over-tx-text-control-for-linux-is-officially-here/llms.txt)
- [Full .NET 9 Support in Text Control .NET Components for ASP.NET Core, Windows Forms, and WPF](https://www.textcontrol.com/blog/2024/11/11/full-net-9-support-in-text-control-net-components-for-asp-net-core-windows-forms-and-wpf/llms.txt)
- [TX Text Control 32.0 Service Pack 4 Released](https://www.textcontrol.com/blog/2024/09/02/tx-text-control-32-0-service-pack-4-released/llms.txt)
- [Service Pack 3: MailMerge Supports SVG Images](https://www.textcontrol.com/blog/2024/04/29/service-pack-3-mailmerge-supports-svg-images/llms.txt)
- [TX Text Control 32.0 Service Pack 3 Released](https://www.textcontrol.com/blog/2024/04/29/tx-text-control-32-0-service-pack-3-released/llms.txt)
