Problem with dynamically populated Contextmenu

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) );
 
J

John B

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top