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);
To create a TableRow and add it in the document tree at 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 at the same time
TableRow row1 = 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 Style Properties.
-
Properties: Gets all table row properties as aTableRowPropertiesobject. For more information on how to use table row properties, see the Style Properties article. -
Cells: Retrieves a collection ofCellelements in the currentTableRow. -
Table: Retrieves the parentTableelement 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 is0. This is a style property. -
RepeatOnEveryPage: Indicates whether this row repeats on every new page. The default value isfalse. 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 istrue. 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 row2 = table.Rows.AddTableRow();
for (int i = 0; i < row2.Table.GridColumnsCount; i++)
{
TableCell cell = row2.Cells.AddTableCell();
cell.Blocks.AddParagraph().Inlines.AddRun(string.Format("Cell 0, {0}", i));
cell.PreferredWidth = new TableWidthUnit(50);
}