[]
        
(Showing Draft Content)

Working with Rows

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 class, which is accessible through the C1FlexGrid.Rows property. This section describes common row-management operations.


Add Row

FlexGrid provides several ways to add rows at run time:

These approaches add rows to the end of the grid. To add a row at a specified location, see Insert Row.

Note: Increasing RowCollection.Count in a bound grid throws an exception.

The following examples demonstrate different approaches to add rows:

// 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";
' 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. To insert multiple rows, use RowCollection.InsertRange.

The following example demonstrates how to insert rows:

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);                 
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. To remove multiple rows, use RowCollection.RemoveRange.

Use C1FlexGrid.RemoveItem to remove a row at a specified index.

In an unbound grid, decreasing RowCollection.Count removes rows from the end of the grid.

// 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;                                        
' 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 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:

C1.Win.C1FlexGrid.Row r;r = c1FlexGrid1.Rows.Add();
r.DataType = typeof(int);
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 property to specify the number of fixed rows.

// Set three rows as fixed
  c1FlexGrid1.Rows.Fixed = 3;                   
' 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 property to specify the number of frozen rows.

// Set first two rows as frozen 
  c1FlexGrid1.Rows.Frozen = 2;
' 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 property.

// Set row count
 c1FlexGrid1.Rows.Count = 15;
' Set row count
c1FlexGrid1.Rows.Count = 15