GridView.SelectCell(Int32, GridColumn) Method

Selects the cell.

Namespace: DevExpress.XtraGrid.Views.Grid

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

public virtual void SelectCell(
    int rowHandle,
    GridColumn column
)
Public Overridable Sub SelectCell(
    rowHandle As Integer,
    column As GridColumn
)

Parameters

Name Type Description
rowHandle Int32

The cell's row handle.

column GridColumn

The cell's column.

Remarks

A cell is located at the specified row and column's intersection.

The SelectCell method does nothing if multiple cell selection (block selection) is disabled. To ensure that block selection is in effect, use the GridView.IsCellSelect property. To unselect a cell use the GridView.UnselectCell method.

When the selection changes, the ColumnView.SelectionChanged event occurs.

The code sample below illustrates how to select the entire grid column when users hold the CTRL button and click on a column's header.


gridView1.OptionsSelection.MultiSelect = true;
gridView1.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CellSelect;
gridView1.MouseDown += GridView1_MouseDown;

private void GridView1_MouseDown(object sender, MouseEventArgs e)
{
    GridView view = sender as GridView;
    GridViewInfo gridInfo = view.GetViewInfo() as GridViewInfo;
    GridHitInfo hitInfo = view.CalcHitInfo(e.Location);

    if (hitInfo.InColumnPanel && e.Button == System.Windows.Forms.MouseButtons.Left && ModifierKeys == Keys.Control)
    {
        for (int i = 0; i < hitInfo.Column.View.RowCount; i++)
            view.SelectCell(i, hitInfo.Column);
        ((DXMouseEventArgs)e).Handled = true;
    }

}
See Also