Skip to main content
All docs
V23.2

How to: Handle a Double-Click on a Grid Row or Cell

  • 3 minutes to read

The BaseView.Editable property specifies whether the Data Grid is editable. Use different techniques depending on this setting.

If Data Grid Is NOT Editable

Handle the BaseView.DoubleClick event. You can use View HitInfo objects to determine which Grid element was clicked.

private void gridView_DoubleClick(object sender, EventArgs e) {
    DXMouseEventArgs ea = e as DXMouseEventArgs;
    GridView view = sender as GridView;
    GridHitInfo info = view.CalcHitInfo(ea.Location);
    if (info.InRow || info.InRowCell) {
        string colCaption = info.Column == null ? "N/A" : info.Column.GetCaption();
        MessageBox.Show(string.Format("DoubleClick on row: {0}, column: {1}.", info.RowHandle, colCaption));
    }
}

If Data Grid Is Editable

If the Data Grid is editable, a double-click on a cell invokes an in-place cell editor. Editors intercept mouse events and the BaseView.DoubleClick event is never fired. You can set the View.OptionsBehavior.EditorShowMode property to Click to force the View.DoubleClick event to fire before an in-place editor is activated. In this case you can handle the DoubleClick event as shown in the previous section.

If you do not wish to change the EditorShowMode property, handle the DoubleClick event at the editor level. To do so, handle the ColumnView.ShownEditor and ColumnView.HiddenEditor events.

BaseEdit editor;
private void gridView_ShownEditor(object sender, EventArgs e) {
    GridView view = sender as GridView;
    editor = view.ActiveEditor;
    editor.DoubleClick += editor_DoubleClick;
}

void gridView_HiddenEditor(object sender, EventArgs e) {
    editor.DoubleClick -= editor_DoubleClick;
    editor = null;
}

void editor_DoubleClick(object sender, EventArgs e) {
    BaseEdit editor = (BaseEdit)sender;
    GridControl grid = editor.Parent as GridControl;
    GridView view = grid.FocusedView as GridView;
    Point pt = grid.PointToClient(Control.MousePosition);
    GridHitInfo info = view.CalcHitInfo(pt);
    if (info.InRow || info.InRowCell) {
        string colCaption = info.Column == null ? "N/A" : info.Column.GetCaption();
        MessageBox.Show(string.Format("DoubleClick on row: {0}, column: {1}.", info.RowHandle, colCaption));
    }
}

Double-Click Row Indicator

To handle Row Indicator Panel double clicks, handle the BaseView.DoubleClick event as demonstrated in the first section.

private void gridView1_DoubleClick(object sender, EventArgs e) {
    DXMouseEventArgs ea = e as DXMouseEventArgs;
    GridView view = sender as GridView;
    GridHitInfo info = view.CalcHitInfo(ea.Location);
    if (info.HitTest == GridHitTest.RowIndicator) {
        MessageBox.Show(string.Format("DoubleClick on row indicator, row #{0}", info.RowHandle));
    }
}

See Also