Dynamic Menus

avromy used Ask the Experts™
How do I dynamically add menus AND sub menus at run time?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

I'm not sure about the submenus, but adding menus is easy.

Create a new top-level menu, say "New menu" in the menu designer and add one menu under this top-level, call it mnuDynamic and set its index property to 0, visible to false and leave caption blank.

Now in run time:
    ' This will create the first item under this New Menu top-level with caption Menu 1
    load mnuDynamic(0)
    mnuDynamic(0).caption = "Menu 1"
    mnuDynamic(0).visible = true

    ' This will create the second item under this New Menu top-level with caption Menu 2
    load mnuDynamic(1)
    mnuDynamic(1).caption = "Menu 2"
    mnuDynamic(1).visible = true

And so on...


I had been aware of how to create a main menu at run time.  That is why I stressed AND A SUBMENU.  
If any one knows of a third party menu control, that would also be helpful.  I looked at a control called ActiveBar, but that does so much more than I need, and thus seems quite complicated.

I think you need to set the Parent property on the menu you're making (mnuDynamic in your example).

Make the Parent an object reference to the item in the main menu, that this submenu will appear from.


   When trying to set the parent property, I get "Invalid Use of Property."

I have code to create menu, popupmenu at runtime with bitmaps.

Go to my website (see profile), and download the file. I also have other code here, I probably will add this code today.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial