# A Step-by-Step Guide to Formatting Table Cells in TX Text Control Programmatically Using C#

> Users can easily insert tables, modify their structure, adjust row and column sizes, and apply formatting to table cells programmatically. This article shows the powerful table features in TX Text Control. It also shows the many ways they can improve your document processing in C#.

- **Author:** Deepika Kathiravan
- **Published:** 2024-06-19
- **Modified:** 2026-11-07
- **Description:** Users can easily insert tables, modify their structure, adjust row and column sizes, and apply formatting to table cells programmatically. This article shows the powerful table features in TX Text Control. It also shows the many ways they can improve your document processing in C#.
- **2 min read** (256 words)
- **Tags:**
  - Windows Forms
  - .NET Framework
  - Tables
- **Web URL:** https://www.textcontrol.com/blog/2024/06/19/a-step-by-step-guide-to-formatting-table-cells-in-tx-text-control-programmatically-using-c-sharp/
- **LLMs URL:** https://www.textcontrol.com/blog/2024/06/19/a-step-by-step-guide-to-formatting-table-cells-in-tx-text-control-programmatically-using-c-sharp/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2024/06/19/a-step-by-step-guide-to-formatting-table-cells-in-tx-text-control-programmatically-using-c-sharp/llms-full.txt

---

TX Text Control has strong document processing capabilities beyond simple text editing. It can simplify the creation and manipulation of tables within documents. This makes it very useful to automate documents like banking statements and reports right within your application.

**Users can easily insert tables, modify their structure, adjust row and column sizes, and apply formatting to table cells programmatically.** This level of control is crucial for managing financial documents. It helps present structured data clearly and professionally.

This article shows the powerful table features in TX Text Control. It also shows the many ways they can improve your document processing in C#.

The following programming categories are discussed in this article:

[Tables - TX Text Control .NET for Windows Forms:](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/tables/)

| Classes |
|---|
| TXTextControl.Table |
| TXTextControl.TableBaseCollection |
| TXTextControl.TableCell |
| TXTextControl.TableCellCollection |
| TXTextControl.TableCellFormat |
| TXTextControl.TableCollection |

### Adding Tables

Start by inserting a simple table through the provided code snippet using the Table class.

```
// Set table identifier. 
int tableID = 10;  

// Add a new table with number of rows and columns. 
textControl1.Tables.Add(2, 5, tableID); 

// Retrieve the newly added table using the tableID. 
TXTextControl.Table table = textControl1.Tables.GetItem(tableID);
```

Result:

![Adding Tables](https://s1-www.textcontrol.com/assets/dist/blog/2024/06/19/b/assets/table1.webp "Adding Tables")

### Formatting TableCells

In any banking statement, it's essential to add header text to tables for displaying transaction details. Handle and format these headers using TableCell and TableCellFormat classes in TX Text Control.

```
// Initialize table headers. 
string[] headers = { "Date", "Description", "Credit", "Debit", "Balance" }; 

for (int i = 1; i <= headers.Length; i++) 
{ 
  // Assign header text to each cell in the first row. 
  table.Cells.GetItem(1, i).Text = headers[i - 1]; 

  // Retrieve and select the cell for formatting. 
  TableCell cell = table.Cells.GetItem(1, i); 

  cell.Select(); 

  // Center align the text and set it to bold. 
  textControl1.Selection.ParagraphFormat.Alignment = TXTextControl.HorizontalAlignment.Center; 
  textControl1.Selection.Bold = true; 

  // Change the text color. 
  textControl1.Selection.ForeColor = Color.Navy; 
}
```

Result:

![Formatting TableCells](https://s1-www.textcontrol.com/assets/dist/blog/2024/06/19/b/assets/table2.webp "Formatting TableCells")

Now that the table headers have content, use the *TableCellFormat* class to improve their visual appeal by formatting the background color and border width.

```
// Create a new TableCellFormat object to apply formatting. 
TXTextControl.TableCellFormat myCellFormat = new TXTextControl.TableCellFormat(); 

// Set the background color. 
myCellFormat.BackColor = Color.LightGray; 

// Specify a bottom border width. 
myCellFormat.BottomBorderWidth = 50; 

// Apply the formatting. 
for (int i = 1; i <= 5; i++) 
{ 
  table.Cells.GetItem(1, i).CellFormat = myCellFormat; 
}
```

Result:

![Formatting TableCells](https://s1-www.textcontrol.com/assets/dist/blog/2024/06/19/b/assets/table3.webp "Formatting TableCells")

### Conclusion

Above are a few properties of the *TableCellFormat* class used for formatting table cells. However, many more are available to customize and automate documents based on your needs. Refer to the image below for further possibilities:

| Properties |
|---|
| BackColor |
| BottomBorderColor |
| BottomBorderWidth |
| BottomTextDistance |
| LeftBorderColor |
| LeftBorderWidth |
| LeftTextDistance |
| NumberFormat |
| RightBorderColor |
| RightBorderWidth |
| RightTextDistance |
| TextType |
| TopBorderColor |
| TopBorderWidth |
| TopTextDistance |
| VerticalAlignment |

---

## About Deepika Kathiravan

Deepika Kathiravan is a developer marketing professional, currently Developer Experience Marketing Lead at Text Control. Before moving into marketing, she had almost eight years of experience in various software industry roles. Following her passion for digital media, Deepika relocated to Germany and earned a Master's in Digital Media from the University of Bremen. She now enjoys blending her technical and marketing expertise by creating developer-centered content and driving strategic growth for the brand.

- [LinkedIn](https://www.linkedin.com/in/deepikakathiravan/)

---

## Related Posts

- [Splitting Tables at Bookmark Positions and Cloning Table Headers](https://www.textcontrol.com/blog/2025/02/13/splitting-tables-at-bookmark-positions-and-cloning-table-headers/llms.txt)
- [Loading and Processing Excel XLSX Spreadsheet Tables into TX Text Control using .NET C#](https://www.textcontrol.com/blog/2024/10/16/loading-and-processing-excel-spreadsheet-tables-into-tx-text-control-using-net-csharp/llms.txt)
- [Text to Table and Table to Text in TX Text Control and C#](https://www.textcontrol.com/blog/2024/06/26/text-to-table-and-table-to-text-in-tx-text-control-and-csharp/llms.txt)
- [Inserting MergeBlocks with the DataSourceManager and Applying Table Styles in C#](https://www.textcontrol.com/blog/2024/04/09/inserting-mergeblocks-with-the-datasourcemanager-and-applying-table-styles-in-csharp/llms.txt)
- [Useful Tricks for Working with Tables](https://www.textcontrol.com/blog/2023/08/04/useful-tricks-for-working-with-tables/llms.txt)
- [Generating Hierarchical Tables from JSON Data in .NET C#](https://www.textcontrol.com/blog/2023/08/03/generating-hierarchical-tables-from-json-data-in-csharp/llms.txt)
- [Table Extension: Remove Empty Columns After Mail Merge](https://www.textcontrol.com/blog/2023/06/08/table-extension-remove-empty-columns-after-mail-merge/llms.txt)
- [Extension Method: Converting Tables to Tabs in C#](https://www.textcontrol.com/blog/2023/03/16/extension-method-converting-tables-to-tabs-in-csharp/llms.txt)
- [Using Accounting Double Underlining in MailMerge Templates](https://www.textcontrol.com/blog/2023/03/02/use-accounting-double-underlining-in-mailmerge-templates/llms.txt)
- [Create a Table of Contents in Windows Forms using C#](https://www.textcontrol.com/blog/2023/01/23/create-toc-in-windows-forms/llms.txt)
- [Official TX Text Control .NET Sample Applications Are Now Hosted on GitHub](https://www.textcontrol.com/blog/2023/01/08/official-tx-text-control-net-sample-applications-are-now-hosted-on-github/llms.txt)
- [Getting Started with Windows Forms (.NET Framework)](https://www.textcontrol.com/blog/2022/09/01/getting-started-with-windows-forms-net-framework/llms.txt)
- [Formatting Numbers in Table Cells](https://www.textcontrol.com/blog/2022/06/21/formatting-numbers-in-table-cells/llms.txt)
- [Merging Merge Block Cells Vertically with Matching Content](https://www.textcontrol.com/blog/2021/10/20/vertically-merge-table-cells-of-merge-blocks-for-matching-content/llms.txt)
- [Auto-Sizing Tables Proportionally](https://www.textcontrol.com/blog/2021/08/05/auto-sizing-tables-proportionally/llms.txt)
- [Automatically Format Numbers in Table Cells](https://www.textcontrol.com/blog/2018/12/10/automatically-format-numbers-in-table-cells/llms.txt)
- [Opening Microsoft Excel files with TX Text Control X16](https://www.textcontrol.com/blog/2018/11/15/opening-microsoft-excel-files-with-tx-text-control-x16/llms.txt)
- [Quick Tip: Merging Cells in Tables](https://www.textcontrol.com/blog/2017/08/14/quick-tip-merging-cells-in-tables/llms.txt)
- [Change Table Width to Fit Document Width - Automatically](https://www.textcontrol.com/blog/2005/02/03/change-table-width-to-fit-document-width-automatically/llms.txt)
