TX Text Control .NET for Windows Forms

Table Class

Class
Namespace
TXTextControl
Package
TXTextControl.TextControl.WinForms.SDK from the private NuGet feed or Text Control Offline Packages
Assembly
TXTextControl.dll
Install
dotnet add package TXTextControl.TextControl.WinForms.SDK .NET 8 and later. For .NET Framework, reference TXTextControl.dll from the setup.

Description

An instance of the Table class represents a table in a Text Control document. It can be obtained from the document's table collection.

Syntax

public class Table

Examples

The following example shows how to split a table.

textControl1.ResetContents();
int myTableId = 10;

textControl1.Tables.Add(10, 3, myTableId);
TXTextControl.Table myTable = textControl1.Tables.GetItem(myTableId);
textControl1.InputPosition =
  new TXTextControl.InputPosition(myTable.Cells.GetItem(3, 1).Start);

if (myTable.CanSplit)
  myTable.Split(TXTextControl.TableAddPosition.After);

// Correct the table IDs after splitting the original table.
foreach (TXTextControl.Table myCurrentTable in textControl1.Tables)
  myCurrentTable.ID = myTableId++;

The following example accesses a Table object and reads its can merge cells value.

var value = table.CanMergeCells;
Console.WriteLine(value);

Members

Properties

PropertyDescription
CanMergeCellsChecks whether table cells can be merged. Table cells can only be merged, if more than one cell in this table is selected.
CanSplitChecks whether this table can be split. A table can only be split if it contains the current input position and no further text is selected.
CanSplitCellsReturns true, if the currently selected table cells are merged.
CellsGets a collection of all table cells the table consists of. The property's value is an object of the type TableCellCollection.
ColumnsGets a collection of all columns the table consists of. The property's value is an object of the type TableColumnCollection.
DescriptiveTextGets or sets a descriptive text for a table. An empty string indicates that the table has no such text. An empty string can also be used to delete a previously set text.
IDGets or sets the table's identifier. It must be between 10 and short.MaxValue.
NestedLevelGets the nested level for the specified table. Top level tables have a level of 1.
NestedTablesGets a collection of all tables nested in this table. The property's value is an object of the type TableBaseCollection.
OuterMostTableGets a table's outermost table. This is a top-level table with a nested level of 1. The property's value is an object of the type Table or null if this table is already a top-level table.
OuterTableGets a table's outer table. The property's value is an object of the type Table or null if this table is a top-level table.
RowsGets a collection of all rows the table consists of. The property's value is an object of the type TableRowCollection.

Methods

MethodDescription
MergeCellsMerges all selected table cells in this table. The Table.CanMergeCells property can be used to determine, if table cells can be merged or not.
SelectSelects the table or a part of the table.
SplitSplits a table below or above the current input position. If the table does not contain the current input position it cannot be split. The Table.CanSplit property can be used to determine if a table can be split or not. If a table is split above the first row a new line is inserted above the table and if a table is split below the last row a new line is inserted below the table. This is useful to insert text above or below a nested table that immediately starts and/or ends at the beginning or the end of the cell in which it is nested.
SplitCellsSplits all selected table cells in this table. Only previously merged cells can be split. The Table.CanSplitCells property can be used to determine, if table cells can be split or not.

Further Reading

  • A Step-by-Step Guide to Formatting Table Cells in TX Text Control Programmatically Using C# –
  • Table Extension: Remove Empty Columns After Mail Merge –
  • Quick Tip: Merging Cells in Tables –
  • Setting the Input Position in TX Text Control –