Problem with dynamically populated Contextmenu

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I have a MenuItem which is was added to the context menu at design time. The
context menu is for a button on a toolbar. At runtime I add and remove
sub-menuitems to and from this menu item. The problem is the dynamically
added items don't always appear.

If I add say 3 menu items and click to see the menu, the sub menu appears
and shows 3 items. This is fine. Now, if I add another item and click to see
the submenu, nothing displays. The arrow is there and there is a count of 4.
I also checked to make sure they're all set to visible and they are.

Any suggestions?

// Add menu item
miShow.MenuItems.Add(itemText, new EventHandler(mi_Click) );

// Remove menu item
miShow.MenuItems.Remove(mi);

//Also tried clearing and re-adding all of them but still no luck
miShow.MenuItems.Clear();
foreach (string s in mystringarray)
miShow.MenuItems.Add(s, new EventHandler(mi_Click) );
 
Joe said:
I have a MenuItem which is was added to the context menu at design time. The
context menu is for a button on a toolbar. At runtime I add and remove
sub-menuitems to and from this menu item. The problem is the dynamically
added items don't always appear.

If I add say 3 menu items and click to see the menu, the sub menu appears
and shows 3 items. This is fine. Now, if I add another item and click to see
the submenu, nothing displays. The arrow is there and there is a count of 4.
I also checked to make sure they're all set to visible and they are.

Any suggestions?

// Add menu item
miShow.MenuItems.Add(itemText, new EventHandler(mi_Click) );

// Remove menu item
miShow.MenuItems.Remove(mi);

//Also tried clearing and re-adding all of them but still no luck
miShow.MenuItems.Clear();
foreach (string s in mystringarray)
miShow.MenuItems.Add(s, new EventHandler(mi_Click) );
Im just guessing here but are you retaining a reference to your added
menu item (mi)?

JB
 
Back
Top