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?