方法 : 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 プロパティによってテーブルの列を操作する