[]
        
(Showing Draft Content)

C1.Win.FlexGrid.C1FlexGridBase.AddItem

AddItem Method

AddItem(string)

Adds a row to the grid and populates the new row with data.

Declaration
public Row AddItem(string item)
Parameters
Type Name Description
string item

String containing the data for the new row. Items are separated by tab characters by default. You can change the separator character using the ClipSeparators property.

Returns
Type Description
Row

A reference to the new row.

Remarks

You can also add and remove rows using the Rows collection. The AddItem(string) method provides a concise syntax for creating the row, populating it with data, and then adding it to the grid.

Before using AddItem(string) to add a large number of rows to the grid, remember to set the Redraw property to false. When finished adding the rows, set Redraw back to its original value. This will significantly improve performance.

Examples

The code below adds 300 rows to the grid.

// suspend painting to improve performance
bool redraw = flex.Redraw;
flex.Redraw = false;

// append 100 rows, using tabs as separators
flex.ClipSeparators = "\t\n";
for (int i = 0; i < 100; i++)
  flex.AddItem("\tcol1\tcol2\tcol3");

// add 100 rows at the top, using pipes as separators
flex.ClipSeparators = "|;";
for (int i = 0; i < 100; i++)
  flex.AddItem("|col1|col2|col3", 0);

// append 100 rows at the bottom, using an object array
object[] items = { "col1", "col2", "col3" };
for (int i = 0; i < 100; i++)
  flex.AddItem(items, flex.Rows.Count, flex.Cols.Fixed);

// restore painting
flex.Redraw = redraw;

AddItem(object[])

Adds a row to the grid and populates the new row with data.

Declaration
public Row AddItem(object[] items)
Parameters
Type Name Description
object[] items

Array of objects that will be assigned to the new row.

Returns
Type Description
Row

A reference to the new row.

AddItem(string, int)

Adds a row to the grid at a specified position and populates the new row with data.

Declaration
public Row AddItem(string item, int index)
Parameters
Type Name Description
string item

String containing the data for the new row. Items are separated by tab characters by default. You can change the separator character using the ClipSeparators property.

int index

Position where the new row will be inserted.

Returns
Type Description
Row

A reference to the new row.

AddItem(object[], int, int)

Adds a row to the grid at a specified position and populates the new row with data.

Declaration
public Row AddItem(object[] items, int rowIndex, int colIndex)
Parameters
Type Name Description
object[] items

Array of objects that will be assigned to the new row.

int rowIndex

Position where the new row will be inserted.

int colIndex

First column to populate with the items in the items array. This parameter is usually set to the index of the first scrollable column.

Returns
Type Description
Row

A reference to the new row.