Skip to main content

VGridRows.Insert(BaseRow, Int32) Method

Inserts a specific row object into the collection at the specified position.

Namespace: DevExpress.XtraVerticalGrid.Rows

Assembly: DevExpress.XtraVerticalGrid.v23.2.dll

NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.VerticalGrid

Declaration

public void Insert(
    BaseRow row,
    int index
)

Parameters

Name Type Description
row BaseRow

A BaseRow class descendant representing the row object to insert into the rows collection.

index Int32

The zero-based location index where a specific row object should be inserted.

Remarks

This method allows you to insert the existing BaseRow descendant object at a specific position within the rows collection. If the index parameter is less than 0, the row object specified by the row parameter is added to the beginning of the rows collection. If the index is equal to or greater than the Count property value then the specified row is appended to the collection. The elements that follow the insertion point move down to accommodate the new element. The indexes of the moved elements are also updated.

To add a row object without specifying a specific position within the collection, use the VGridRows.Add method. If you want to add an array of rows to the collection, use the VGridRows.AddRange method.

To remove the previously added row object, use the collection’s VGridRows.Remove or Clear() method.

Example

The following example creates a row object of the EditorRow type that will contain the middle initials of employees. The VGridRows.Insert method is used to insert the row prior to a row containing last names. The required position is obtained by using the VGridRows.IndexOf method, which is passed with a row object specified by its name.

Note that if a row containing last names does not exist (or is specified by the wrong name), the rowLN variable contains null (Nothing in Visual Basic). In this case, the VGridRows.IndexOf method returns -1 and the new row (rowMI) is inserted at the beginning of the collection.

using DevExpress.XtraVerticalGrid;
using DevExpress.XtraVerticalGrid.Rows;

private void InsertRow() {
    // creaing a new row bound to a specific field and specifying its caption
    EditorRow rowMI = new EditorRow("middle_initial");
    rowMI.Properties.Caption = "Middle Initial";

    // obtaining a row object containing last names specifying its name
    BaseRow rowLN = vGridControl1.Rows["LastName"];

    // inserting the row before a row containing last names
    vGridControl1.Rows.Insert(rowMI, vGridControl1.Rows.IndexOf(rowLN));
}
See Also