Getting Started

This very easy-to-use getting started tutorial shows how to use the Template Designer TX Text Control Words with a sample template and database and illustrates how to integrate the merging process into your .NET based application.

Add Reporting to Your Applications in 3 Easy Steps

Used TX Text Control controls:

  • TXTextControl.DocumentServer.MailMerge
  • TXTextControl.TextControl

Relevant API Links

This very easy-to-use getting started tutorial shows how to use the Template Designer with a sample database and templates and how to integrate the merging process into your .NET application.

Image

Step 1: Create Your Application

1. Open Visual Studio and create a new Windows Forms application.

  • From the Toolbox, drag and drop an instance of TextControl onto your form.
  • Open the SmartTag in the upper right corner of the TextControl object and visit each wizard link to add additional controls (button bar, rulers, status bar) and connect them by clicking Arrange Controls Automatically.
  • Add a MailMerge component from the toolbox to the form.

Image

2. Find the SmartTag of the MailMerge component in the component tray. Click Connect to Text Component to connect MailMerge with the TextControl instance.

Image

3. In the same SmartTag of MailMerge, click Start Template Designer to open TX Text Control Words.

Image

Step 2: Open Sample Database and Template

1. Load the sample template Invoice using the Open Sample Template menu entry from the main menu File.

Image

2. Open the Select Data Source drop-down button of the Reports ribbon tab and click Load Sample Database.

Image

3. Make sure that the table Sales_SalesOrderHeader is selected from the drop-down list button Select Master Table.

Image

4. Now select Preview Merge Fields from the Preview ribbon tab. Confirm the opened dialog with OK to select the number of records for the preview process.

Image

5. Uncheck Preview Merge Fields and save the template as a DOCX document using the Save As... menu entry from the main menu File.

Image

Image

Step 3: Integrate into Application

1. Back in Visual Studio, open the MailMerge SmartTag, click TemplateFile... and browse for the saved template from Step 2.5 in the opened dialog box.

2. Add a MenuStrip to the form, create a menu item called Merge and double-click this item to open the event handler.

Image

Add the following code and change the XML file location in line 1 to match your TX Text Control installation path:

string sDBPath = @"C:\Program Files\Text Control GmbH\TX Text Control 26.0.NET for Windows Forms\Samples\Demo\sample_db.xml";

DataSet ds = new DataSet();
ds.ReadXml(sDBPath);

mailMerge1.Merge(ds.Tables["Sales_SalesOrderHeader"], true)
Dim sDBPath As String = "C:\Program Files\Text Control GmbH\TX Text Control 26.0.NET for Windows Forms\Samples\Demo\sample_db.xml"

Dim ds As New DataSet()
ds.ReadXml(sDBPath)

mailMerge1.Merge(ds.Tables("Sales_SalesOrderHeader"), True);

3. Compile and start the application, click the menu item Merge to start the merge process.