# Working with Columns

FlexGrid for WinForms lets you perform basic column operations such as setting count, adding, deleting, set data type etc. Learn how to work with columns.

## Content

A grid consists of rows and columns. Columns typically contain a specific type of information, while rows represent records for individual items.
**FlexGrid** manages columns through the [ColumnCollection](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.ColumnCollection.html) class, which is accessible through the [C1FlexGrid.Cols](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.C1FlexGridBase.Cols.html) property. This section describes common column-management operations.
![C1WinForms FlexGrid Column operation demo](https://cdn.mescius.io/document-site-files/images/2f10b028-0ae8-4c29-a102-4d67578c339b/image-20260701.b6aa56.png)

***

## Add Column

FlexGrid provides two ways to add columns through the `ColumnCollection` class:

* Call the [Add](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.Add.html) method.
* Increase the [Count](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.Count.html) property.

When a column is added to a bound grid, **FlexGrid** creates it as an unbound column.

```csharp
// Approach1: 
// Use Add method of the column collection
    C1.Win.C1FlexGrid.Column c;
c = c1FlexGrid1.Cols.Add();
c.Caption = "New Column";
//Approach2:
// Change Count property of the column collection
    c1FlexGrid1.Cols.Count += 1;
c1FlexGrid1.Cols[c1FlexGrid1.Cols.Count - 1].Caption = "New Column";
```

```vbnet
' Approach1: 
    ' Use Add method of the column collection
    Dim c As C1.Win.C1FlexGrid.Column
c = c1FlexGrid1.Cols.Add()
c.Caption = "New Column"
'Approach2:
    ' Change Count property of the column collection
    c1FlexGrid1.Cols.Count += 1
c1FlexGrid1.Cols(c1FlexGrid1.Cols.Count - 1).Caption = "New Column"         
```

***

## Delete Column

Remove a column by using the [ColumnCollection.Remove](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.Remove.html) method.
In an unbound grid, decreasing [ColumnCollection.Count](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.Count.html) removes columns from the end of the collection. To remove multiple columns, use [ColumnCollection.RemoveRange](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.RemoveRange.html).

```csharp
// Approach1:
// Delete 2nd column using the Remove method of column collection      
   c1FlexGrid1.Cols.Remove(2);
// Approach2:
// Delete the last column by changing the Count property
   c1FlexGrid1.Cols.Count -= 1;
// Approach3:
// Delete four columns starting from 2nd by using the RemoveRange method 
   c1FlexGrid1.Cols.RemoveRange(2, 4);                                      
```

```vbnet
' Approach1:
    ' Delete 2nd column using the Remove method of column collection      
    c1FlexGrid1.Cols.Remove(2)
' Approach2:
    ' Delete the last column by changing the Count property
    c1FlexGrid1.Cols.Count -= 1
' Approach3:
    ' Delete four columns starting from 2nd by using the RemoveRange method 
    c1FlexGrid1.Cols.RemoveRange(2, 4)       
```

***

## Insert Column

Insert a column at a specified position by using [ColumnCollection.Insert](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.Insert.html). To insert multiple columns, use [InsertRange](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.InsertRange.html).
These methods create unbound columns even when **FlexGrid** is bound to a data source.

```csharp
C1.Win.C1FlexGrid.Column c;
// Approach1:
// Insert a column at the 2nd position using the Insert method
   c = c1FlexGrid1.Cols.Insert(2);
c.Caption = "Inserted Column";
// Approach2:
// Insert three columns at 2nd position using the InsertRange method
// c1FlexGrid1.Cols.InsertRange(2, 3);                            
```

```vbnet
Dim c As C1.Win.C1FlexGrid.Column
'Approach1:
'Insert a column at the 2nd position using the Insert method
 c = c1FlexGrid1.Cols.Insert(2)
c.Caption = "Inserted Column"
'Approach2:
'Insert three columns at 2nd position using the InsertRange method
'c1FlexGrid1.Cols.InsertRange(2, 3)                                      
```

***

## Set Column Count

When FlexGrid is bound to a data source, the number of columns corresponds to the number of fields in the data source.
In unbound mode, set the number of columns by assigning a value to the [ColumnCollection.Count](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.CellRangeCollection.Count.html) property.

```csharp
// Set column count
 c1FlexGrid1.Cols.Count = 4;
```

```vbnet
' Set column count
c1FlexGrid1.Cols.Count = 4        
```

***

## Set Data Type

In a bound **FlexGrid**, column data types are derived from the data source.
In unbound mode, set a column data type by using the [Column.DataType](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCol.DataType.html) property. The data type can also be configured at design time from the **Column Tasks** menu.
After a data type is assigned, cells in the column accept input that matches the specified type.

```csharp
// Set data type of first column
 c1FlexGrid1.Cols[1].DataType = typeof(int);                     
```

```vbnet
' Set data type of first column
c1FlexGrid1.Cols(1).DataType = GetType(Integer)
```

***

## Set Fixed Column

Fixed columns remain visible on the left side of the grid and cannot be edited.
Use the [ColumnCollection.Fixed](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.Footers.Fixed.html) property to specify the number of fixed columns.

```csharp
// Set one column as fixed
c1FlexGrid1.Cols.Fixed = 1;                            
```

```vbnet
' Set one column as fixed
c1FlexGrid1.Cols.Fixed = 1          
```

***

## Set Frozen Column

Frozen columns remain visible during horizontal scrolling and can still be edited.
Use the [ColumnCollection.Frozen](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowColCollection.Frozen.html) property to specify the number of frozen columns.

```csharp
// Set first four columns as frozen 
c1FlexGrid1.Cols.Frozen = 4;
```

```vbnet
' Set first four columns as frozen 
c1FlexGrid1.Cols.Frozen = 4       
```