GitHunt
DE

DevExpress-Examples/winforms-grid-single-button-click-multiple-selection

Implement a single button click in multiple selection mode.




WinForms Data Grid - Implement a single button click in multiple selection mode

This sample shows how to force the ButtonClick event for a cell editor when the user clicks the editor button (in this example, the dropdown button). The example handles the GridView.MouseDown event to obtain hit information under the mouse cursor, activate the cell editor, and determine whether the editor button is pressed:

private void gridView1_MouseDown(object sender, MouseEventArgs e) {
    if ((Control.ModifierKeys & Keys.Control) != Keys.Control) {
        GridView view = sender as GridView;
        GridHitInfo hi = view.CalcHitInfo(e.Location);
        if (hi.InRowCell) {
            if (hi.Column.RealColumnEdit.GetType() == typeof(RepositoryItemComboBox)) {
                view.FocusedRowHandle = hi.RowHandle;
                view.FocusedColumn = hi.Column;
                view.ShowEditor();
                // Forces button click. 
                ButtonEdit edit = (view.ActiveEditor as ComboBoxEdit);
                Point p = view.GridControl.PointToScreen(e.Location);
                p = edit.PointToClient(p);
                EditHitInfo ehi = (edit.GetViewInfo() as ButtonEditViewInfo).CalcHitInfo(p);
                if (ehi.HitTest == EditHitTest.Button) {
                    ((ComboBoxEdit)view.ActiveEditor).ShowPopup();
                    PerformClick(edit, new ButtonPressedEventArgs(ehi.HitObject as EditorButton));
                    ((DevExpress.Utils.DXMouseEventArgs)e).Handled = true;
                }
            }
        }
    }
}
void PerformClick(ButtonEdit editor, ButtonPressedEventArgs e) {
    if (editor == null || e == null) return;
    MethodInfo mi = typeof(RepositoryItemButtonEdit).GetMethod("RaiseButtonClick",
        BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
    if (mi != null)
        mi.Invoke(editor.Properties, new object[] { e });
}

Files to Review

Does This Example Address Your Development Requirements/Objectives?

(you will be redirected to DevExpress.com to submit your response)

Languages

C#50.4%Visual Basic .NET49.6%

Contributors

Other
Created April 8, 2018
Updated February 24, 2026
DevExpress-Examples/winforms-grid-single-button-click-multiple-selection | GitHunt