# TableColumnCollection Class

> An instance of the TableColumnCollection class contains all columns of a table in a Text Control document represented through objects of the type TableColumn. It can be obtained with the Table.Columns property. The TableColumnCollection class implements the IEnumerable and the ICollection interfaces.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Reference
- **Kind:** Class
- **Namespace:** `TXTextControl`
- **Package:** `TXTextControl.TextControl.WinForms.SDK` (assembly `TXTextControl.dll`, from the private NuGet feed or Text Control Offline Packages)
- **.NET Framework:** reference `TXTextControl.dll` from the setup
- **Inherits:** `TXTextControl.TablePartCollection`
- **Implements:** `System.Collections.ICollection`, `System.Collections.IEnumerable`
- **Path:** TX Text Control .NET for Windows Forms > Reference > TXTextControl > TableColumnCollection Class
- **1827 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/tablecolumncollection/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/tablecolumncollection/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/tablecolumncollection/llms-full.txt

---

### Description

An instance of the TableColumnCollection class contains all columns of a table in a Text Control document represented through objects of the type [TableColumn](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/tablecolumn/llms-full.txt). It can be obtained with the [Table.Columns](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/table/columns-property/llms-full.txt) property. The TableColumnCollection class implements the IEnumerable and the ICollection interfaces.

### Syntax

```csharp
public sealed class TableColumnCollection : TablePartCollection
```

```vbnet
Public NotInheritable Class TableColumnCollection
    Inherits TablePartCollection
```

### Examples

The following example shows how to use the table column collection.

```csharp
int myLastCol = myTable.Columns.Count;
TXTextControl.TableColumn myCol = myTable.Columns.GetItem(myLastCol);
TXTextControl.TableCell myCell = myTable.Cells.GetItem(1, myLastCol);
int myNewWidth = (int)(myCol.Width / 2);

textControl1.InputPosition = new TXTextControl.InputPosition(myCell.Start - 1);

if (myTable.Columns.CanAdd)
{
    myCol.Width = myNewWidth;
    myTable.Columns.Add(TXTextControl.TableAddPosition.After);
}
```

```vbnet
Dim MyLastCol As Integer = MyTable.Columns.Count
Dim MyCol As TXTextControl.TableColumn = MyTable.Columns.GetItem(MyLastCol)
Dim MyCell As TXTextControl.TableCell = MyTable.Cells.GetItem(1, MyLastCol)
Dim MyNewWidth As Integer = CInt(MyCol.Width / 2)

TextControl1.InputPosition = New TXTextControl.InputPosition(MyCell.Start - 1)

If MyTable.Columns.CanAdd Then
    MyCol.Width = MyNewWidth
    MyTable.Columns.Add(TXTextControl.TableAddPosition.After)
End If
```

The following example creates a small report table and works with its structure.

```csharp
textControl.Tables.Add(3, 3, 10);
Table table = textControl.Tables.GetItem(10);
TableColumnCollection tableColumnCollection = table.Columns;
```

```vbnet
textControl.Tables.Add(3, 3, 10)
Dim table As Table = textControl.Tables.GetItem(10)
Dim tableColumnCollection As TableColumnCollection = table.Columns
```

---

## In This Section

- [TableColumnCollection.Add Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/tablecolumncollection/add-method/llms-full.txt): Adds a new table column at the current text input position.
- [TableColumnCollection.CanAdd Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/tablecolumncollection/canadd-property/llms-full.txt): Gets a value indicating whether a new column can be inserted at the current input position. This property does not check for protected TextFields and/or protected document sections. To perform this use in addition the TextControl.CanEdit property.
- [TableColumnCollection.CanRemove Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/tablecolumncollection/canremove-property/llms-full.txt): Gets a value indicating whether table columns can be removed. Columns can be removed if either the current text input position is in a table or if a part of a table is selected.
- [TableColumnCollection.CopyTo Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/tablecolumncollection/copyto-method/llms-full.txt): Copies the elements of the collection to an array, starting at a particular index.
- [TableColumnCollection.GetItem Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/tablecolumncollection/getitem-method/llms-full.txt): Gets a particular table column from the collection.
- [TableColumnCollection.Remove Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/tablecolumncollection/remove-method/llms-full.txt): Removes the table column at the current text input position or all selected table columns when a text selection exists.

---

## Nearby

- **Previous:** [TableColumn.Width Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/tablecolumn/width-property/llms-full.txt)
- **Next:** [TableColumnCollection.Add Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/tablecolumncollection/add-method/llms-full.txt)
