tags:

views:

1106

answers:

4

I have a ContextMenuStrip that contains a submenu of dynamically generated ToolStripMenuItems. There are up to 80 sub menu items. Pressing the first letter of a desired menu item selects it correctly, but if the item happens to be out of the visible range (in a range handled by the scroll arrows), it isn't displayed - the user has to press the up arrow and then the down arrow for the desired option to be displayed & focussed on the screen.

As an example, I have 6 items starting with "m" but only 3.5 are visible. I hit m one and the first item is highlighted, I hit m 3 more times and I can see half a selected row (it's at the bottom of the visible area), hit m two more times, and I can't see the select row, then m one more time and the first m entry is visible and selected again.

By default ToolStripMenuItems (TSMI) don't have key listeners available, however if I subclass the TSMI I can catch ProcessDialogKey and ProcessCmdKey and manually select the right option, but I am unable to scroll the toolstrip sub menu down to ensure my option is visible.

Any tips on how to either a) scroll a tool strip's sub menu or b) allow the sub menu to use multiple columns (and hope the user doesn't have a ridiculously low resolution).

A: 

Have you tried the KeyPress event on the ContextMenuStrip? You might be able to detect the key press that changes the selected item then use the ToolStripMenuItem.Selected property on each item to determine which one is selected. Then use AutoScrollOffset on the ContextMenuStrip to scroll the item into view.

Or, you could use the old ContextMenu control instead - it's items have a Select event.

Jeff Yates
The KeyPress event on the CMS doesn't get fired for sub menus.I can catch the ProcessDialogKey and select the right element, but performing "select" on the correct element doesn't scroll the submenu down to display the selected item.AutoScrollOffset doesn't seem to work for submenus
BrianH
As ContextMenuStrip is derived from ScrollableControl (and ignoring the fact that it is hidden) have you tried setting AutoScroll to true?
Jeff Yates
I get a NotsupportedException "ToolStrip doesn't support the AutoScroll property." when I tried to set the AutoScroll property on the ContextMenuStrip or on the problematic ToolStripMenuItem.
BrianH
A: 

Hello Brian

Have you find out the solution of scrolling subitems? I have a similar problem and ffpf suggestions haven't work for me.

Thank you

Jason

A: 

I ran into this problem. I don't remember the exact solution (Let me know if you can't find it) but, basically, ToolStripMenu has a property for 'top-most item index'.

Just set the newly-selected item (the 4th 'm', for example) as the top-most item index and WinForms will handle the rest.

Good luck!

AlexeyMK
A: 

Hi AlexeyMK.

I can't find this property.

To explain you the situation my program is a ContextMenuStrip (which inherits from ToolStripDropDownMenu : ToolStripDropDown : ToolStrip).

One of ContexMenutStrip item is a DropDownItems collection that include: - a ToolStripTextBox - some ToolStripMenuItems (so the problem is in a submenu)

When I put focus on textbox I would like to scroll my dropdown to make visible the current selected item.

It's the normal behavior of DropDownItem but since I put focus on first item (textbox) menu can't scroll even if selection mark is correctly on current item.

I don't understand...