Shortcut key on ToolStripMenuItem not working
-
I'm sure I'm missing something obvious here but I don't see it ... I am constructing a menu at runtime from an XML document, which is being read into a data class created with the xsd utility. This is all fine. As part of constructing the menu itself, I assign to the ShortcutKeys property:
if (!string.IsNullOrEmpty(level.Accelerator)) menuItem.ShortcutKeys = (Keys)TypeDescriptor.GetConverter(typeof(Keys)).ConvertFromString(level.Accelerator);
Accelerator is a property auto-generated by xsd and looks like "Ctrl+N", "F4" etc, and this line is running when it should. The result is that my menu is correctly built, and shortcut keys appear in the menuitems, but pressing the key doesn't cause the Click event to fire. If I first open that menu, the shortcuts fire (i.e. if I open 'File' and press Ctrl+O, the open dialog appears), but they do not if the menu on which the item lives is not opened. (Obviously this is not correct behaviour.) Just wondering if someone has seen something similar and can tell me what simple step I am missing.