Skip to main content

VGridRows.IndexOf(BaseRow) Method

Searches for a specific row object and returns the zero-based index of the first occurrence within the rows collection.

Namespace: DevExpress.XtraVerticalGrid.Rows

Assembly: DevExpress.XtraVerticalGrid.v24.1.dll

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

Declaration

public int IndexOf(
    BaseRow Row
)

Parameters

Name Type Description
Row BaseRow

A BaseRow derived object representing the row to locate within the collection.

Returns

Type Description
Int32

The zero-based index of the first occurrence of a specific row within the rows collection, if found; otherwise -1.

Remarks

The IndexOf method enables you to determine where the row object specified by the row parameter is located within the rows collection represented by the VGridRows object. This method searches the rows collection for the specified row and if found returns the BaseRow.Index value for the first occurrence. If no instance is found, a negative one (-1) is returned. The collection of rows is searched forward beginning with the first element and ending with the last one.

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