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

Open + Highlight Context Menu Item

3 Answers 75 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Cameron Hart
Top achievements
Rank 1
Cameron Hart asked on 19 May 2009, 04:03 AM
Hey guys,

I'm trying to polish up the keystroke count in an application. I have a gridview. If the gridview is in focus and the enter key is pressed, I want the row context menu to be opened and the first item in that menu to be highlighted.

Here's my code:

        private void gvwManifestLines_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) 
        { 
            if (e.KeyCode == Keys.Return) 
            { 
                this.rowContextMenu.Show(this.gvwManifestLines, 15, 15); 
                this.rowContextMenu.Items[0].CanFocus = true
                this.rowContextMenu.Items[0].Focus(); 
            } 
            // remaining code omitted for brevity. 
 

Interestingly, if I just hit enter twice I am actually activating the menu item in question, so my Keystroke count has gone down by one (it cuts out a 'down' Keystroke). However, the item is not being highlighted when it is granted focus, and this is going to confuse my users.

Is there a way of getting the context menu to highlight the item?

3 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 20 May 2009, 07:30 AM
Hello Cameron Hart,

You should call SelectItem method of the DropDown. Please consider the code snippet below:

private void gvwManifestLines_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) 
    if (e.KeyCode == Keys.Return) 
    { 
        this.rowContextMenu.Show(this.gvwManifestLines, 15, 15); 
        this.rowContextMenu.DropDown.SelectItem(this.rowContextMenu.Items[0]); 
    } 

I hope this helps. Should you have further questions, don't hesitate to ask.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Cameron Hart
Top achievements
Rank 1
answered on 20 May 2009, 09:48 PM
Spot on.

Thanks for that. I've been using these controls for a while now - either I've gotten a lot better with them, or the controls have gotten a much more robust the last few updates. I'm impressed.
0
Jack
Telerik team
answered on 21 May 2009, 12:04 PM
Hi Cameron Hart,

Thank you for the positive feedback.

Yes, we constantly work to improve our controls and we hope that they will become even more robust when we release our next version - Q2 2009. Stay tuned.

If you have any other questions, please don't hesitate to write us.

Kind regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
ContextMenu
Asked by
Cameron Hart
Top achievements
Rank 1
Answers by
Jack
Telerik team
Cameron Hart
Top achievements
Rank 1
Share this question
or