This topic discusses various basic operations which can be performed on a column.
FlexGrid lets you add new columns using the Columns property of FlexGrid class, which gets the collection of columns of the grid. For this purpose, the C1DataCollectionList<T> class provides the Add(T item) method. This class is a member of C1.DataCollection namespace of C1.DataCollection assembly, and it works like a Data collection wrapper. Also, note that if a new column is added to a bound grid using this method, it is added as an unbound column only.
Following is the code snippet to add column to the FlexGrid control.
C# |
コードのコピー
|
---|---|
// バインドされたグリッドにバインドされていない列を追加します。 グリッドの最後に列が追加されているかどうかを確認します flexGrid1.Columns.Add(new GridColumn { Header = "New Unbound Col", Width = new GridLength(1, GridUnitType.Star), MinWidth = 150, AllowMerging = false, HeaderHorizontalAlignment = HorizontalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }); |
To delete a particular column from the grid, you can use the Columns property of FlexGrid class and RemoveAt (int index) method of the C1DataCollectionList<T> class. This method removes the list item at the specified index.
Following is the code snippet to delete column from the FlexGrid.
C# |
コードのコピー
|
---|---|
// 列「FirstName」を削除します
flexGrid1.Columns.RemoveAt(1);
|
To insert a column in FlexGrid at a specific location, you can use the Columns property of FlexGrid class and Insert (int index, T item) method of the C1DataCollectionList<T> class, which inserts an item at the specified index.
Following is the code snippet to insert a column in the FlexGrid column at the specified location.
C# |
コードのコピー
|
---|---|
// 0番目の位置に列を挿入し、プロパティ「FirstName」でバインドします flexGrid1.Columns.Insert(0, new GridColumn { Header = "BoundCol-FName", Width = new GridLength(1, GridUnitType.Star), MinWidth = 120, AllowMerging = false, HeaderHorizontalAlignment = HorizontalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Binding = "FirstName" }); |
Frozen columns, similar to fixed columns, are non-scrollable but can be edited by the user. In FlexGrid, frozen columns can be set by using FrozenColumns and FrozenRows property provided by the FlexGrid class.
To set frozen columns in the FlexGrid control, use the code below.