TableRow
TableRow is a flow document element that defines a row within a Table. It contains a collection of TableCell elements.
Inserting a TableRow
You can use the code snippet from Example 1 to create a TableRow and add it in a Table.
Example 1: Create a TableRow and add it to a table
TableRow row = new TableRow(document);
table.Rows.Add(row);
In order to create a TableRow and add it in the document tree in the same time, you can use the AddTableRow() method of the Rows collection property of the table.
Example 2: Create a TableRow and add it to a table in the same time
TableRow row = table.Rows.AddTableRow();
Modifying a TableRow
The TableRow element exposes several properties that allow you to customize its layout. Some of the properties are Style properties.
Style properties are properties that can be inherited from a style. For more information about styles see this article.
Properties: Gets all table row properties as TableRowProperties object. More info on how to use table row properties can be found in Style Properties article.
Cells: Retrieves a collection of Cell elements in the current TableRow.
Table: Retrieves the parent Table element of the row.
GridRowIndex: Represents the index of the row in the table grid.
TableCellSpacing: Specifies the spacing between adjacent cells and the edges of the table. The value is in device independent pixels (1/96 inch). The default value is 0. This is a Style property.
RepeatOnEveryPage: Indicates whether this row should be repeated on every new page. The default value is false. This property cannot be derived from a style.
CanSplit: Specifies whether the content of the row can be split across multiple pages. The default value is true. This property cannot be derived from a style.
Height: Specifies the row height. This property cannot be derived from a style.
Operating with a TableRow
Add TableCell Elements to a TableRow
Example 3 shows how to add a number of TableCell elements in a TableRow.
Example 3: Add TableCell objects to a TableRow
TableRow row = table.Rows.AddTableRow();
for (int i = 0; i < row.Table.GridColumnsCount; i++)
{
TableCell cell = row.Cells.AddTableCell();
cell.Blocks.AddParagraph().Inlines.AddRun(string.Format("Cell 0, {0}", i));
cell.PreferredWidth = new TableWidthUnit(50);
}