Skip to main content
A newer version of this page is available. .

GridView.SelectRow(Int32) Method

Selects the specified row.

Namespace: DevExpress.XtraGrid.Views.Grid

Assembly: DevExpress.XtraGrid.v19.1.dll

Declaration

public override void SelectRow(
    int rowHandle
)

Parameters

Name Type Description
rowHandle Int32

An integer value which specifies the handle of the row to select.

Remarks

The SelectRow method selects the specified row and adds it to the current selection. If multiple selection is disabled (the ColumnViewOptionsSelection.MultiSelect option is set to false) the SelectRow method does nothing.

Example

The following code shows how to select rows that contain “Mexico” in the Country column and copy data from these rows.

ColumnView.SelectRow-example.png

using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base;

ColumnView view = gridControl1.MainView as ColumnView;
GridColumn colCountry = view.Columns["Country"];
GridColumn colCompany = view.Columns["CompanyName"];
if (colCountry == null || colCompany == null) return;

// Enable multiple row selection mode.
view.OptionsSelection.MultiSelect = true;
view.ClearSelection();
int rowHandle = -1;
// Select rows that contain 'Mexico' in the Country column.
while (rowHandle != GridControl.InvalidRowHandle) {
    rowHandle = view.LocateByDisplayText(rowHandle + 1, colCountry, "Mexico");
    view.SelectRow(rowHandle);
}
int[] selectedRowHandles = view.GetSelectedRows();
if (selectedRowHandles.Length > 0) {
    // Move focus to the first selected row.
    view.FocusedRowHandle = selectedRowHandles[0];
    // Copy the selection to the clipboard
    view.CopyToClipboard();
    // Copy the selected company names to a Memo editor.
    memoEdit1.Text = "";
    for (int i = 0; i < selectedRowHandles.Length; i++)
        memoEdit1.Text += view.GetRowCellDisplayText(selectedRowHandles[i], colCompany) + "\r\n";
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the SelectRow(Int32) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also