# Working with Rows

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

## Content

A grid contains rows and columns. Columns represent specific types of data, while rows represent records associated with individual items.
FlexGrid manages rows through the [RowCollection](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.html) class, which is accessible through the [C1FlexGrid.Rows](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.C1FlexGridBase.Rows.html) property. This section describes common row-management operations.

***

## Add Row

FlexGrid provides several ways to add rows at run time:

* Call [RowCollection.Add](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.Add.html) or [C1FlexGrid.AddItem](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.C1FlexGridBase.AddItem.html) to add a row.
* Call [RowCollection.Count](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.Count.html) in an unbound grid to increase rows.

These approaches add rows to the end of the grid. To add a row at a specified location, see [Insert Row](/componentone/docs/win/online-flexgrid/concepts/basic-row-operations#insert-row).

>type=note
> Note: Increasing **RowCollection.Count** in a bound grid throws an exception.

The following examples demonstrate different approaches to add rows:

```csharp
// Approach1:
// Use the RowCollection.Add method to add row
 C1.Win.C1FlexGrid.Row r;
 r = c1FlexGrid1.Rows.Add();
// Set data
 r[1] = "New Row 2";
 // Approach2: 
 // Use AddItem method to add row and set data
  c1FlexGrid1.AddItem("" + "\t" + "New Row 1");
// Approach3:
// Use the RowCollection.Count property to add row
 c1FlexGrid1.Rows.Count += 1;
// Set data
 c1FlexGrid1[c1FlexGrid1.Rows.Count - 1, 1] = "New Row 3";
```

```vbnet
' Approach1:
 ' Use the RowCollection.Add method to add row
 Dim r As C1.Win.C1FlexGrid.Row
r = c1FlexGrid1.Rows.Add()
' Set data
 r(1) = "New Row 2"
' Approach2: 
 ' Use AddItem method to add row and set data
 c1FlexGrid1.AddItem("" & vbTab & "New Row 1")
' Approach3:
 ' Use the RowCollection.Count property to add row
 c1FlexGrid1.Rows.Count += 1
' Set data
 c1FlexGrid1(c1FlexGrid1.Rows.Count - 1, 1) = "New Row 3"    
```

***

## Insert Row

Insert a row at a specified position by using [RowCollection.Insert](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.Insert.html). To insert multiple rows, use [RowCollection.InsertRange.](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.InsertRange.html)
The following example demonstrates how to insert rows:

```csharp
C1.Win.C1FlexGrid.Row r;
// Approach1:
// Use the Insert method to insert row at second position
 r = c1FlexGrid1.Rows.Insert(2);
r[1] = "Inserted row";
// Approach2:
// Use the InsertRange method to add three rows at second position
// c1FlexGrid1.Rows.InsertRange(2, 3);                 
```

```vbnet
Dim r As C1.Win.C1FlexGrid.Row
 ' Approach1:
 ' Use the Insert method to insert row at second position
 r = c1FlexGrid1.Rows.Insert(2)
 r(1) = "Inserted row"
 ' Approach2:
 ' Use the InsertRange method to add three rows at second position
 ' c1FlexGrid1.Rows.InsertRange(2, 3)
```

***

## Remove Row

Remove a row by using [RowCollection.Remove](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.Remove.html). To remove multiple rows, use [RowCollection.RemoveRange](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.RemoveRange.html).
Use [C1FlexGrid.RemoveItem](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.C1FlexGridBase.RemoveItem.html) to remove a row at a specified index.
In an unbound grid, decreasing [RowCollection.Count](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCollection.Count.html) removes rows from the end of the grid.

```csharp
// Approach1:
// Remove second row using RowCollection.Remove method
c1FlexGrid1.Rows.Remove(2);
// Approach1:
// Remove second row using the RemoveItem method
c1FlexGrid1.RemoveItem(2);
// Approach3:
// Remove 3 rows starting from second using the RemoveRange method
c1FlexGrid1.Rows.RemoveRange(2, 3);
// Approach4:
// Remove last row using the RowCollection.Count property 
c1FlexGrid1.Rows.Count -= 1;                                        
```

```vbnet
' Approach1:
 ' Remove second row using RowCollection.Remove method
 c1FlexGrid1.Rows.Remove(2)
' Approach1:
 ' Remove second row using the RemoveItem method
 c1FlexGrid1.RemoveItem(2)
' Approach3:
 ' Remove 3 rows starting from second using the RemoveRange method
 c1FlexGrid1.Rows.RemoveRange(2, 3)
' Approach4:
 ' Remove last row using the RowCollection.Count property 
 c1FlexGrid1.Rows.Count -= 1    
```

***

## Set Data Type

In a bound FlexGrid, column data types are derived from the data source.
In unbound mode, set the data type by using the [Row.DataType](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.RowCol.DataType.html) or `Column.DataType` property. When both properties are set, the column data type takes precedence.
The following example demonstrates how to configure the data type of a row:

```csharp
C1.Win.C1FlexGrid.Row r;r = c1FlexGrid1.Rows.Add();
r.DataType = typeof(int);
```

```vbnet
Dim r As C1.Win.C1FlexGrid.Rowr = c1FlexGrid1.Rows.Add()
r.DataType = GetType(int)    
```

***

## Set Fixed Row

Fixed rows remain visible at the top of the grid and cannot be edited.
Use the [RowCollection.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 rows.

```csharp
// Set three rows as fixed
  c1FlexGrid1.Rows.Fixed = 3;                   
```

```vbnet
' Set three rows as fixed
c1FlexGrid1.Rows.Fixed = 3       
```

***

## Set Frozen Row

Frozen rows remain visible during scrolling and can still be edited.
Use the [RowCollection.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 rows.

```csharp
// Set first two rows as frozen 
  c1FlexGrid1.Rows.Frozen = 2;
```

```vbnet
' Set first two rows as frozen 
c1FlexGrid1.Rows.Frozen = 2    
```

***

## Set Row Count

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

```csharp
// Set row count
 c1FlexGrid1.Rows.Count = 15;
```

```vbnet
' Set row count
c1FlexGrid1.Rows.Count = 15                    
```