共用方式為


HOW TO:透過 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();

下列範例會傳回資料表中裝載 (Host) 的 TableRowGroup 項目數目。

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

下列範例會以傳址 (By Reference) 方式移除特定資料列群組。

            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();

請參閱

工作

HOW TO:透過 RowGroups 屬性管理資料表的資料列群組

HOW TO:透過 Blocks 屬性管理 FlowDocument

HOW TO:透過 Columns 屬性管理資料表的資料行