keyboardtoolstrip

Reset 'keyboard cues' in ToolStrip


We display a sub-dialog from a cell of our grid control. The dialog contains a ToolStrip with items with ampersands to quickly access them from the keyboard. All works fine: we can press ALT to show those keyboard cues, and/or issue such keystrokes as ALT+M, C to activate the corresponding ToolStrip commands.

But if we open one of our ToolStrip's drop-down and do not make choice, then click outside of our subdialog to close it this way, the ToolStrip goes crazy. When we open the dialog again, the keyboard cues are initially underlined, the last top-level item may be highlighted, and our ALT-commands do not work.

How to reset a ToolStrip to make it working properly in this scenario?


Solution

  • Earlier we used the ToolStripDropDown's Hide method in the OnHide event of our subdialog to close every active drop-down menu automatically when the dialog is closed, but the proper solution should be:

    fToolStripDropDownButtonClear.DropDown.Close(ToolStripDropDownCloseReason.ItemClicked)
    

    I.e. need to issue the Close method exactly with the 'ItemClicked' parameter value.