Using Shortcut Keys for opening and closing DropDowns in a grid is always a better idea which avoids the hassle of using the mouse while editing some data in the grid. With this blog, we will explain an approach on how one can use Shortcut Keys (keys could be decided as per convenience) to open and close the DropDowns in the Column(s) and the FilterBar of the ComponentOne TrueDBGrid for Winforms. The code is very simple and self explanatory. The only thing which needs to be taken care off here is the tracking the Open and Close states of the DropDowns in C1TrueDBGrid. We will Override the ProcessCmdKey method to implement custom short-cut keystroke handling and will use the Key combination {Shift+F1} for opening the DropDowns and {Shift+F2} for closing them.


protected override bool ProcessCmdKey(ref Message msg, Keys keyData)  
{  
    if (keyData == (Keys.Shift | Keys.F1)) //Shortcut key to be used  
    {  
        if (ddstate == 0)  
            shrtcutopen = 0;  

        /\*CODE TO OPEN THE DROPDOWNS IN THE GRID CELLS WITH SHORTCUT KEY {SHIFT+F1}\*/  
        if (shrtcutopen == 0)  
        {  
            SendKeys.Send("%{DOWN}");  
            shrtcutopen = 1;  
        }  

        ++counter;  
        /\*CODE TO OPEN THE DROPDOWNS IN THE FILTERBAR WITH SHORTCUT KEY {SHIFT+F1}\*/  
        if (filter == 0)//&&  counter == 1)  
        {  
            if (c1TrueDBGrid1.FilterActive)  
            {  
                SendKeys.Send("%{DOWN}");  
                filter = 1;  
                shrtcutopen = 0;  
            }  
        }  
       return false;  
    }  
    if (keyData == (Keys.Shift | Keys.F2)) //Shortcut key to be used  
    {  
        /\*CODE TO CLOSE THE DROPDOWNS IN THE GRID CELLS WITH SHORTCUT KEY {SHIFT+F2}\*/  
        if (shrtcutclose == 1)  
        {  
            SendKeys.Send("%{UP}");  
            shrtcutclose = 0;  

        }  

        /\*CODE TO CLOSE THE DROPDOWNS IN THE FILTERBAR WITH SHORTCUT KEY {SHIFT+F2}\*/  
        if (filter == 1)  
        {  
            SendKeys.Send("%{UP}");  
            filter = 0;  
            shrtcutopen = 0;  
        }  
            return false;  
    }  
    if (keyData == Keys.Enter)  
    {  
        filter = 0;  
    }  

    return base.ProcessCmdKey(ref msg, keyData);  
}  

In addition some other events like DropDownOpen, DropDownClose, FilterButtonClick and SelChange are used to handle the behaviour. ShortcutKeys Download CS Sample Download VB Sample