Skip to content

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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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