Strange menuitem problem. Help!

mickn66

Regular
Joined
Nov 2, 2002
Messages
53
My program has a notifyicon in the system tray, and this notifyicon has a context menu called mnuContextMenu. The context menu has a number of menuitems, some of which have submenus of their own. My program has procedures to add and remove menuitems and submenuitems from mnuContextMenu. Everything seems to work fine. However, when I add a new item to the submenu of one of the “main items” in mnuContextMenu, the “main item” in question will no longer expand and show the submenu, even though it still has that little arrow on it to indicate that there is a submenu.

In otherwords, let’s say the starting items for mnuContextMenu are “one” “two” and “three.” And let’s say “two” has a submenu consiting of “aaaa” “bbbb” “cccc” and “dddd”. My program tries to add a new subitem with text “eeee” to menuitem “two” – the problem is that after that happens, whenever I hover the mouse over item “two” – it will no longer expand to show me the subitems “aaaa” through “eeee” – even though “two” still has the arrow indicating that it has a submenu. Furthermore, when I check via the command window, I can see that menuitem “two” is still considered a Parent, and it’s menuitems.count has in fact increased.

The code that I used to do this, I have a variable called curMain (declared as a menuitem) which, at the point in question, is set to represent one of the menuitems in mnuContextMenu (in the hypothetical above, curMain points to the menuitem that has “two” as the text (curMain.text = “two”). So my code to add the subitem to curMain is: curMain.MenuItems.add(inp), where inp is a string= “eeee”. Once this instruction is executed, mnuContextMenu will no longer expand to show the submenu under “two” – although all the other submenus still work.

I hope I’ve explained this well. Any help would be greatly appreciated! Thanks.
 
Try this solution for ContextMenu Problem

I recently have the same problem you described in Visual Basic .NET and I tried many ways to solve it and found one, try this if you are still interested in it:

Dim index as Integer = ContextMenu1.MenuItems.IndexOf(mnuitem)
ContextMenu1.MenuItems.Remove(mnuitem)
... ' do something with the MenuItem, add or remove items
ContextMenu1.MenuItems.Add(index, mnuitem)

PS: Sorry for my bad English I'm from Germany
 
Back
Top