Back to Devexpress

VGridRows.IndexOf(BaseRow) Method

windowsforms-devexpress-dot-xtraverticalgrid-dot-rows-dot-vgridrows-dot-indexof-x28-devexpress-dot-xtraverticalgrid-dot-rows-dot-baserow-x29.md

latest4.7 KB
Original Source

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.v25.2.dll

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

Declaration

csharp
public int IndexOf(
    BaseRow Row
)
vb
Public Function IndexOf(
    Row As BaseRow
) As Integer

Parameters

NameTypeDescription
RowBaseRow

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

|

Returns

TypeDescription
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.

csharp
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));
}
vb
Imports DevExpress.XtraVerticalGrid
Imports DevExpress.XtraVerticalGrid.Rows

Private Sub InsertRow()
    ' creaing a new row bound to a specific field and specifying its caption
    Dim RowMI As 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))
End Sub

See Also

BaseRow

Index

Rows

VGridRows Class

VGridRows Members

DevExpress.XtraVerticalGrid.Rows Namespace