It has been a while since I have been written about the Windows Forms version of TX Text Control. And that is not because we give the Windows Forms version less priority - it is just my current dedication towards reporting, ASP.NET and web development.

The client versions including Windows Forms and WPF have a very high priority for us. Sure, web application's popularity is growing fast and our ASP.NET team is doing a great job to fulfill all requests and requirements from our users. But we understand that millions of end-users are using Windows desktop applications with TX Text Control, so we are investing time and money into the development of new and improved features for these platforms as well.

In this sample, we show how to use a BindingNavigator and a BindingSource to preview merge results.

Windows Forms: Preview mail merge results with the BindingNavigator and a BindingSource

The sample form consists of a TextControl with an attached button bar, rulers and status bars. Additionally, a MailMerge component, a BindingNavigator and a BindingSource has been added to the form.

Windows Forms: Preview mail merge results with the BindingNavigator and a BindingSource

The BindingSource property of the BindingNavigator is set to the instance of the BindingSource.

In code, a new DataSet is created by reading an XML data file. The DataSource property of the BindingSource is set to the root table of the created DataSet.

// import XML into a new DataSet object
DataSet ds = new DataSet();
ds.ReadXml("data.xml");
bindingSource1.DataSource = ds.Tables[0];
view raw form1.cs hosted with ❤ by GitHub

In the CurrentChanged event of the BindingSource, a temporary table clone with only the current row is created and used to merge the template.

private void bindingSource1_CurrentChanged(object sender, EventArgs e)
{
// retrieve the current DataRow
DataRow drCurrent = ((DataRowView)bindingSource1.Current).Row;
// create a temporary copy with only the current row
DataTable dtTemp = drCurrent.Table.Clone();
dtTemp.ImportRow(drCurrent);
// merge the template with the cloned table
mailMerge1.Merge(dtTemp);
}
view raw form1.cs hosted with ❤ by GitHub

This way, the current data row is merged instantly when the user navigates to another row using the BindingNavigator control.

Download the sample from GitHub and test it on your own.