Articles in this section
Category / Section

How to detect whether a 'CTRL' key or a 'SHIFT' key is down in WinForms GridControl?

1 min read

Handle the Shift and Ctrl key

To know whether the CTRL or SHIFT key is currently down or not, you can find out by using the following codes.

C#

void gridControl1_MouseDown(object sender, MouseEventArgs e)
{
    // Checks whether the Ctrl key is down.
    if ((Control.ModifierKeys & Keys.Control) != 0)
    {
        Console.WriteLine("Control Key is down");
    }
    //Checks whether the Shift key is down.
    if ((Control.ModifierKeys & Keys.Shift) != 0)
    {
        Console.WriteLine("Shift Key is down");
    }
}

VB

Private Sub gridControl1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    'Checks whether the Ctrl key is down.
    If (Control.ModifierKeys And Keys.Control) <> 0 Then
        Console.WriteLine("Control Key is down")
    End If
    'Checks whether the Shift key is down.
    If (Control.ModifierKeys And Keys.Shift) <> 0 Then
        Console.WriteLine("Shift Key is down")
    End If
End Sub

 

GridControl with shift and control keys in WinForms Grid Control

Figure 1: Grid Control with Shift and Control keys handling

Samples:

C#: KeyHandling-CS.zip

VB: KeyHandling-VB.zip

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied