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…

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
Related Posts
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.
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…
Paste Special: The Easy Way to Implement
In an older sample, I showed how to implement a paste special functionality by accessing the clipboard directly using .NET functionality. In version 15.0, we implemented this functionality…
How to Remove All Section Breaks in a Document?
With version 14.0, we introduced document section breaks that allow you to have different page formats in the same document. Version 15.0 implements page columns that can be adjusted section-wise.…
Batch Printing: How to Print Documents in One Print Job
A typical requirement when printing loads of documents is managing the print jobs. A group of separate documents might be subsumed in a single print job. We just published a new sample in our…