Products Technologies Demo Docs Blog Support Company

Working with Exceptions in TX Text Control .NET for Windows Forms

TX Text Control .NET for Windows Forms replaces the ActiveX Error event with structured exception handling using Try Catch. This VB.NET sample demonstrates catching table collection errors and applying the conditional When clause to filter for specific exception conditions.

Working with Exceptions in TX Text Control .NET for Windows Forms

Customers who are porting their VB 6.0 ActiveX application to .NET often ask me, if we forgot the implementation of the Error event. To understand why TX Text Control .NET for Windows Forms does not offer such an event, you have to understand how structured error handling works. This really simple sample shows you how you can use Try Catch in VB.NET to do something similar to the On Error Resume Next functionality.

The GetItem method of the TableBaseCollection gets a particular table from the collection with a specific table identifier. In most cases, you could use a For Each statement to iterate through the tables. But in some cases you need to get one specific table. Anyway, if for some reasons, the table is not longer in the current document, you will get an error message saying that the object reference is not set to an instance of an object. In other words: the table does not exist.

This error message can be handled by yourself using the Try Catch statement:

Try
    TextControl1.Tables.GetItem(11).Cells.GetItem(2, 2).Text = "TableCell"
Catch ex As Exception
    MessageBox.Show("My personalized error message!")
End Try

This is just a purely fictional situation. One last tip for the Try Catch statement: you could add a When clause, so that the error is only trapped, if the When clause is fulfilled.

Catch ex As Exception When myFlag = False

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

Windows FormsWPF.NET

Create a Table of Contents in Windows Forms using C#

This article explains how to create a table of contents in Windows Forms using the ribbon or programmatically. Creating a table of contents is required to organize large documents.


Windows FormsList.NET

Two Ways to Restart Numbered Lists in TX Text Control

In TX Text Control, numbered lists are continued by default and need to be reset when required. There is more than one way if you want to restart numbered lists in a document. In this article, two…


.NETSample

Paste Special: The Easy Way to Implement

TX Text Control version 15.0 introduced a ClipboardFormat parameter on the Paste method, enabling native Paste Special functionality. The GetClipboardFormats method returns all available clipboard…


.NETSampleSections

How to Remove All Section Breaks in a Document?

TX Text Control 15.0 adds per-section page column support alongside existing section breaks. To remove all section breaks programmatically, iterate through SectionCollection using…


.NETPrintingSample

Batch Printing: How to Print Documents in One Print Job

Batch printing multiple documents as a single print job using TX Text Control relies on a .NET PrintDocument with PrintPage and QueryPageSettings events. Each page is rendered individually via the…

Share on this blog post on: