Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/how-to-build-a-table-programmatically.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

4.3 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Build a Table Programmatically 03/30/2017
csharp
vb
tables [WPF], creating programmatically
e3ca88f3-6e94-4b61-82fc-42104c10b761

How to: Build a Table Programmatically

The following examples show how to programmatically create a xref:System.Windows.Documents.Table and populate it with content. The contents of the table are apportioned into five rows (represented by xref:System.Windows.Documents.TableRow objects contained in a xref:System.Windows.Documents.Table.RowGroups%2A object) and six columns (represented by xref:System.Windows.Documents.TableColumn objects). The rows are used for different presentation purposes, including a title row intended to title the entire table, a header row to describe the columns of data in the table, and a footer row with summary information. Note that the notion of "title", "header", and "footer" rows are not inherent to the table; these are simply rows with different characteristics. Table cells contain the actual content, which can be comprised of text, images, or nearly any other [!INCLUDETLA#tla_ui] element.

Example

First, a xref:System.Windows.Documents.FlowDocument is created to host the xref:System.Windows.Documents.Table, and a new xref:System.Windows.Documents.Table is created and added to the contents of the xref:System.Windows.Documents.FlowDocument.

[!code-csharpTableSnippets#_TableCreate] [!code-vbTableSnippets#_TableCreate]

Example

Next, six xref:System.Windows.Documents.TableColumn objects are created and added to the table's xref:System.Windows.Documents.Table.Columns%2A collection, with some formatting applied.

Note

Note that the table's xref:System.Windows.Documents.Table.Columns%2A collection uses standard zero-based indexing.

[!code-csharpTableSnippets#_TableCreateColumns] [!code-vbTableSnippets#_TableCreateColumns]

Example

Next, a title row is created and added to the table with some formatting applied. The title row happens to contain a single cell that spans all six columns in the table.

[!code-csharpTableSnippets#_TableAddTitleRow] [!code-vbTableSnippets#_TableAddTitleRow]

Example

Next, a header row is created and added to the table, and the cells in the header row are created and populated with content.

[!code-csharpTableSnippets#_TableAddHeaderRow] [!code-vbTableSnippets#_TableAddHeaderRow]

Example

Next, a row for data is created and added to the table, and the cells in this row are created and populated with content. Building this row is similar to building the header row, with slightly different formatting applied.

[!code-csharpTableSnippets#_TableAddDataRow] [!code-vbTableSnippets#_TableAddDataRow]

Example

Finally, a footer row is created, added, and formatted. Like the title row, the footer contains a single cell that spans all six columns in the table.

[!code-csharpTableSnippets#_TableAddFooterRow] [!code-vbTableSnippets#_TableAddFooterRow]

See also