ColumnView.SelectRow(Int32) Method
Adds a row (card) to the current selection.
Namespace: DevExpress.XtraGrid.Views.Base
Assembly: DevExpress.XtraGrid.v24.1.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
Declaration
Parameters
Name | Type | Description |
---|---|---|
rowHandle | Int32 | An integer value identifying the row (card) to be selected by its handle. |
Remarks
This method does nothing when multiple selections are prohibited (the ColumnViewOptionsSelection.MultiSelect property is set to false) or if the specified row handle is invalid.
Refer to the Multiple Row and Cell Selection topic for additional information on selecting rows and cards.
Note
Detail pattern Views do not contain data and they are never displayed within XtraGrid. So, the SelectRow member must not be invoked for these Views. The SelectRow member can only be used with Views that display real data within the Grid Control. Use the following methods to access these Views with which an end user interacts at runtime.
- GridControl.MainView - returns the top most View in a grid;
- GridControl.FocusedView - returns the focused View;
- GridControl.DefaultView - returns the currently maximized View;
- the sender parameter of View specific events;
- GridView.GetDetailView - returns a detail clone View for a specific master row.
Example
The following code shows how to select rows that contain “Mexico” in the Country column and copy data from these rows.
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";
}