# VB6 and Dynamic Menu construction



## koala (Apr 18, 2001)

Maybe this question is better directed at a more specialized VB6 forum, if so could someone please direct me to the appropriate URL. Thanks.

In a VB6 application I want to build a multilayed popup menu on the fly. I know how to do it when there is only the root entry and x number of subordinates, but what about the following:

Root Item
....Level 1 Item 0
...........Level 2 Item 0
...........Level 2 Item 1
....Level 1 Item 1
...........Level 2 item 2
etc etc

I want to be able to "LOAD" Level1 items and the "LOAD" Level2 items but how do I get it to make a Level2 item subordinate to a particular Level1 item?

Thanks very much.


----------



## YSB (Mar 7, 1999)

I'm not 100% sure but the way I see it you'll have to make the menu structure at design time. You can then give each layer of each level a different name so it can have it's own control array. 

When loading a menu item at run time, the new item will be identical to it's parent. Therefor it will appear in the same submenu as it's parent. You can make invisible menu items in a layout something like this:


RootMenuItem 
...Level1A 
......Level2A Item 0
...Level1B 
......Level2B Item 0
...Level1C
......Level2C Item 0
.
.
.
...Level1N
......Level2N Item 0


Make more levels than you expect to need and set the visible property to those you don't need to false. Since each submenu has it's own name and index, you just load a new menu item in the menu you want. For exapmle, if you Load a new 'Level 2B Item 1' it will show up under 'Level1B'.

The way I understand it I don't think it's possible to add a submenu to a menu that was created at run-time because at least one submenu item for that menu must exist at design time. 

I you find a way to create a submenu at run-time for a parent menu that was created on the fly let us know. I'd be very curious to see it.

Good Luck!


----------



## koala (Apr 18, 2001)

Thank you YSB.

After I posted the initial request, further investigations revealed what you had deduced, viz you can only add menu items to an already constructed layout - I believe you cannot add (LOAD) a new "Level 1" item and then LOAD a "Level 2" item to that new "Level 1".

I would love to know how MS does it in the Menu Manager of VB6.

Thanks again.

BTW: besides this forum, do you have a favorite specialized VB forum?


----------



## THoey (Feb 12, 2001)

This site is pretty good, but if you want a site that specializes in a particular language or platform, try http://www.tek-tips.com . That is actually where I heard of this site at...


----------

