This topic discusses various basic operations which can be performed on a column.
When grid is bound to a data source, the number of columns is determined by the number of fields available in the data source. However, in the case of unbound mode, you can set any arbitrary value in the Count property of the ColumnCollection class to set the number of columns to be displayed in the grid.
Use the code below to set the number of columns to be added to WinForms FlexGrid in unbound mode.
FlexGrid provides two ways to add a new column using the ColumnCollection class. You can either use Add method or increment the value of Count property provided by the class to add new columns. Also, note that if a new column is added to a bound grid using these methods, it is added as an unbound column only.
Following are the two approaches to add column to a WinForms FlexGrid.
To delete a particular column from the grid, you can use Remove method of the ColumnCollection class and specify the column you want to delete as its parameter. In the unbound grid, you can also reduce the number of columns by changing the value of Count property. This removes columns from the end of the column collection. The ColumnCollection class also provides RemoveRange method which allows you to remove a range of columns.
Below code snippet shows all the three approaches to delete column from the WinForms FlexGrid.
To insert a column in FlexGrid at a specific location, you can use Insert method of the ColumnCollection class which lets you specify the position where columns are to be inserted. You can also insert multiple columns in the grid by using the InsertRange method. These methods add the unbound columns only, even if the grid is a bound grid.
Use any of the following approaches to insert a column in the WinForms FlexGrid at the specified location.
In case of a bound FlexGrid, data type of each bound column is automatically picked from the data source depending on the data. However, in the case of unbound mode, you can set the data type of columns by specifying the DataType property of Column class. You can also set the Data Type property at design time by using the Column Tasks menu. For more information on tasks menus, see Tasks Menus. Note that when a particular data type is set to a FlexGrid column, its cells accept the user input of keys accepted by the data type only. For instance, you can not input alphabets in a Numeric type cell.
Set the data type of an unbound column in WinForms FlexGrid as shown in the code below.
Fixed columns refer to the columns with non-editable cells which are always visible in the left hand side of the grid even if user scrolls the grid horizontally. In FlexGrid, fixed columns can be set using Fixed property of the ColumnCollection class. This property accepts an integer value that specifies the number of columns to be fixed.
Use the code below to set one column as fixed in the WinForms FlexGrid.
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 Frozen property provided by the ColumnCollection class.
To set frozen columns in the WinForms FlexGrid, use the code below.