Take the 2-minute tour ×

Is there a way to assign shortcut keys to the standard navigation ToolStrip Items in a BindingNavigator?

The items that get added using the .AddStandardItems method are of type ToolStripItem which doesn't have a ShortcutKeys property.

I tried to cast to ToolStripMenuItem , but it fails.

 public void ConfigureMyNavigator()
               // Adds ToolStripItems which don't support shortcut keys           

                // Adds a ToolStripMenuItem which can support a shortcut key
                var button = new ToolStripMenuItem
                    Size = new Size(0, 0),
                    Text = "Save",
                    ShortcutKeys = (Keys)Shortcut.CtrlS,
                    ToolTipText = "Press Ctrl+S to save"
                button.Click += tsmi_Click;


                //   This fails with invalid cast exception
                ((ToolStripMenuItem)m_navigator.Items[1]).ShortcutKeys = (Keys)Shortcut.AltLeftArrow;


I guess I could replace the toolstripitems with toolstripmenuitems one by one, but feel this is rather awkward.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You can listen for key commands and then raise the click of the appropriate ToolStripButton. Override the ProcessCmdKey method in your form code:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    switch (keyData)
        case (Keys.Alt | Keys.Left):
        case (Keys.Alt | Keys.Right):

    return base.ProcessCmdKey(ref msg, keyData);
share|improve this answer
Yay! Thank you! –  kirsten g Mar 9 '13 at 4:25
add comment

You can override the AddStandardItems method and overload the ToolStripMenuItem's constructor to accept ToolStripItem as a parameter for easier creation of the items.

But it's still sort of "replacing the items one by one".

share|improve this answer
Is there a way to override AddStandardItems and still retain the way the position text works? At the moment I cant see how overriding is any better than simply not calling AddStandardItems - and adding the buttons one by one. In overriding AddStandardItems, I need to know how to hook the buttons up to the events, where to get the icons from, and how to make the record number text work the same way –  kirsten g Mar 3 '13 at 19:03
it probably is not any better, it's just reusable –  Matus Mar 3 '13 at 21:19
add comment

Your Answer


