如何:通过 RowGroups 属性操作表的行组

此示例演示可通过 RowGroups 属性对表的行组执行的部分较常见操作。

示例

下面的示例创建一个新表,然后使用 Add 方法向该表的 RowGroups 集合内添加列。

            Dim tbl As New Table()
            Dim rowGroupsToAdd As Integer = 4
            For x As Integer = 0 To rowGroupsToAdd - 1
                tbl.RowGroups.Add(New TableRowGroup())
            Next x
Table tbl = new Table();
int rowGroupsToAdd = 4;
for (int x = 0; x < rowGroupsToAdd; x++)
    tbl.RowGroups.Add(new TableRowGroup());

下面的示例插入一个新的 TableRowGroup。 将在索引位置 0 插入新列,这会使其成为该表中的第一个新行组。

注意注意

TableRowGroupCollection 集合使用从零开始的标准索引。

            tbl.RowGroups.Insert(0, New TableRowGroup())
tbl.RowGroups.Insert(0, new TableRowGroup());

下面的示例向该表中的特定 TableRowGroup(由索引指定)中添加几行。

                Dim rowsToAdd As Integer = 10
                For x As Integer = 0 To rowsToAdd - 1
                    tbl.RowGroups(0).Rows.Add(New TableRow())
                Next x
int rowsToAdd = 10;
for (int x = 0; x < rowsToAdd; x++)
    tbl.RowGroups[0].Rows.Add(new TableRow());

下面的示例访问该表内第一个行组中行的某些任意属性。

            ' Alias the working TableRowGroup for ease in referencing.
            Dim trg As TableRowGroup = tbl.RowGroups(0)
            trg.Rows(0).Background = Brushes.CornflowerBlue
            trg.Rows(1).FontSize = 24
            trg.Rows(2).ToolTip = "This row's tooltip"
// Alias the working TableRowGroup for ease in referencing.
TableRowGroup trg = tbl.RowGroups[0];
trg.Rows[0].Background = Brushes.CornflowerBlue;
trg.Rows[1].FontSize = 24;
trg.Rows[2].ToolTip = "This row's tooltip";

下面的示例向该表中的特定 TableRow(由索引指定)中添加几个单元格。

                Dim cellsToAdd As Integer = 10
                For x As Integer = 0 To cellsToAdd - 1
                    tbl.RowGroups(0).Rows(0).Cells.Add(New TableCell(New Paragraph(New Run("Cell " & (x + 1)))))
                Next x
int cellsToAdd = 10;
for (int x = 0; x < cellsToAdd; x++)
    tbl.RowGroups[0].Rows[0].Cells.Add(new TableCell(new Paragraph(new Run("Cell " + (x + 1)))));

下面的示例访问第一个行组内第一行中单元格的某些任意方法和属性。

            ' Alias the working for for ease in referencing.
            Dim row As TableRow = tbl.RowGroups(0).Rows(0)
            row.Cells(0).Background = Brushes.PapayaWhip
            row.Cells(1).FontStyle = FontStyles.Italic
            ' This call clears all of the content from this cell.
            row.Cells(2).Blocks.Clear()
// Alias the working for for ease in referencing.
TableRow row = tbl.RowGroups[0].Rows[0];
row.Cells[0].Background = Brushes.PapayaWhip;
row.Cells[1].FontStyle = FontStyles.Italic;
// This call clears all of the content from this cell.
row.Cells[2].Blocks.Clear();

下面的示例返回由表承载的 TableRowGroup 元素的数量。

            Dim rowGroups As Integer = tbl.RowGroups.Count
int rowGroups = tbl.RowGroups.Count;

下面的示例将按引用移除特定的行组。

            tbl.RowGroups.Remove(tbl.RowGroups(0))
tbl.RowGroups.Remove(tbl.RowGroups[0]);

下面的示例将按索引移除特定的行组。

            tbl.RowGroups.RemoveAt(0)
tbl.RowGroups.RemoveAt(0);

下面的示例将从表的行组集合中移除所有的行组。

            tbl.RowGroups.Clear()
tbl.RowGroups.Clear();

请参见

任务

如何:通过 RowGroups 属性操作表的行组

如何:通过 Blocks 属性操作 FlowDocument

如何:通过 Columns 属性操作表列