This is a migrated thread and some comments may be shown as answers.

Ctrl+enter on check box header cell

3 Answers 104 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 30 Nov 2010, 03:23 AM
Hi,

I'm using the checkbox header class from here: http://www.telerik.com/support/kb/winforms/gridview/add-check-uncheck-all-check-box-in-the-header-cell.aspx

I need to handle users pressing Ctrl+enter to perform an action on all selected rows. The problem I am having is this: if you press Ctrl+enter after checking the check box in the header cell, the check box interprets this as a click and de-selects all the rows in the grid, and consequently no action is performed.

If I select another cell after checking the header check box, it works fine. I have tried selecting another cell programmatically, but the problem still occurs.

How can I prevent Ctrl+enter from triggering a click on the checkbox and still have it raise the Datagrid.KeyDown event?

Thanks,
Matt

3 Answers, 1 is accepted

Sort by
0
Matthew
Top achievements
Rank 1
answered on 03 Dec 2010, 07:16 AM
Hi all,

I have managed to fix the problem.
in your checkboxheadercell class find the checkbox_ToggleStateChanged method. After the code which loops through the rows and checks/unchecks them, call this.Focus();
this takes focus away from the checkbox so that subsequent actions are not picked up by the checkbox.

Matt
0
Emanuel Varga
Top achievements
Rank 1
answered on 03 Dec 2010, 08:36 AM
Hello Matthew,

You could also use a custom grid behavior for this, catch the Cntrl+Enter KeyDown event, handled = true, and add your logic there, then the keypress will not be sent to the checkbox so no actions will be performed.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 03 Dec 2010, 08:43 AM
Like so:

radGridView1.GridBehavior = new CustomGridBehavior();
 
public class CustomGridBehavior : BaseGridBehavior
{
    public override bool ProcessKeyDown(KeyEventArgs keys)
    {
        if (keys.KeyData == (Keys.Control | Keys.Enter))
        {
            // do some processing here
            return true;
        }
        else
        {
            return base.ProcessKeyDown(keys);
        }
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
Tags
GridView
Asked by
Matthew
Top achievements
Rank 1
Answers by
Matthew
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Share this question
or