HOW TO:透過 Columns 屬性管理資料表的資料行
更新:2007 年 11 月
本範例示範可透過 Columns 屬性對表格欄執行的幾項常見作業。
範例
下列範例會建立新的表格,並用 Add 方法將欄加入至表格的 Columns 集合中。
Table tbl = new Table();
int columnsToAdd = 4;
for (int x = 0; x < columnsToAdd; x++)
tbl.Columns.Add(new TableColumn());
下列範例會插入新的 TableColumn。新的欄會插入至索引位置 0,成為表格中新的第一欄。
![]() |
---|
TableColumnCollection 集合使用以零起始的標準索引。 |
tbl.Columns.Insert(0, new TableColumn());
下列範例會依據欄的索引,存取 TableColumnCollection 集合中特定欄的任意屬性。
tbl.Columns[0].Width = new GridLength(20);
tbl.Columns[1].Background = Brushes.AliceBlue;
tbl.Columns[2].Width = new GridLength(20);
tbl.Columns[3].Background = Brushes.AliceBlue;
下列範例會取得表格中目前裝載的欄數。
int columns = tbl.Columns.Count;
下列範例會以傳址 (By Reference) 方式移除特定欄。
tbl.Columns.Remove(tbl.Columns[3]);
下列範例會依據索引移除特定欄。
tbl.Columns.RemoveAt(2);
下列範例會移除表格欄集合中所有的欄。
tbl.Columns.Clear();
請參閱
工作
HOW TO:透過 RowGroups 屬性管理資料表的資料列群組
HOW TO:透過 Blocks 屬性管理 FlowDocument
HOW TO:透過 RowGroups 屬性管理資料表的資料列群組