Cara: Memanipulasi Grup Baris Tabel melalui Properti Grup Baris
Contoh ini menunjukkan beberapa operasi yang lebih umum yang dapat dilakukan pada grup baris tabel melalui RowGroups properti .
Membuat tabel baru menggunakan metode Tambahkan
Contoh berikut membuat tabel baru lalu menggunakan Add metode untuk menambahkan kolom ke koleksi tabel RowGroups .
Table tbl = new Table();
int rowGroupsToAdd = 4;
for (int x = 0; x < rowGroupsToAdd; x++)
tbl.RowGroups.Add(new TableRowGroup());
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
Menyisipkan TableRowGroup baru
Contoh berikut menyisipkan baru TableRowGroup. Kolom baru disisipkan pada posisi indeks 0, menjadikannya grup baris pertama baru dalam tabel.
Catatan
Koleksi TableRowGroupCollection menggunakan pengindeksan berbasis nol standar.
tbl.RowGroups.Insert(0, new TableRowGroup());
tbl.RowGroups.Insert(0, New TableRowGroup())
Menambahkan baris ke TableRowGroup
Contoh berikut menambahkan beberapa baris ke tertentu TableRowGroup (ditentukan oleh indeks) dalam tabel.
int rowsToAdd = 10;
for (int x = 0; x < rowsToAdd; x++)
tbl.RowGroups[0].Rows.Add(new TableRow());
Dim rowsToAdd As Integer = 10
For x As Integer = 0 To rowsToAdd - 1
tbl.RowGroups(0).Rows.Add(New TableRow())
Next x
Mengakses properti baris dalam grup baris pertama
Contoh berikut mengakses beberapa properti arbitrer pada baris dalam grup baris pertama dalam tabel.
// 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";
' 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"
Menambahkan sel ke TableRow
Contoh berikut menambahkan beberapa sel ke tertentu TableRow (ditentukan oleh indeks) dalam tabel.
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)))));
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
Metode akses dan properti pada sel dalam grup baris pertama
Contoh berikut mengakses beberapa metode dan properti arbitrer pada sel di baris pertama dalam grup baris pertama.
// 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();
' 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()
Mendapatkan jumlah elemen TableRowGroup dalam tabel
Contoh berikut mengembalikan jumlah TableRowGroup elemen yang dihosting oleh tabel.
int rowGroups = tbl.RowGroups.Count;
Dim rowGroups As Integer = tbl.RowGroups.Count
Menghapus grup baris menurut referensi
Contoh berikut menghapus grup baris tertentu menurut referensi.
tbl.RowGroups.Remove(tbl.RowGroups[0]);
tbl.RowGroups.Remove(tbl.RowGroups(0))
Menghapus grup baris menurut indeks
Contoh berikut menghapus grup baris tertentu menurut indeks.
tbl.RowGroups.RemoveAt(0);
tbl.RowGroups.RemoveAt(0)
Menghapus semua grup baris dari kumpulan grup baris tabel
Contoh berikut menghapus semua grup baris dari kumpulan grup baris tabel.
tbl.RowGroups.Clear();
tbl.RowGroups.Clear()
Baca juga
.NET Desktop feedback
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk