Web Menu with Child

The following code produces a menu but not quite what I want. As the image shows that MenuB is linked to a blank space at the end of the MainMenu. How do I attach MenuB to say, the 2nd item in MainMenu?

Dim MainMenu As New WebMenuitem
Dim MenuB As New WebMenuitem

MainMenu.Append(New WebMenuItem("MainMenu 2"))
MainMenu.Append(New WebMenuItem("MainMenu 3"))
MainMenu.Append(New WebMenuItem("MainMenu 4"))

MenuB.Append(New WebMenuItem("MenuB 55"))
MenuB.Append(New WebMenuItem("MenuB 77"))

MainMenu.Append(MenuB)

WebToolBarMenu(Me.ItemWithName("Menu2")).Menu = MainMenu


Dim MainMenu As New WebMenuitem
Dim MenuA As WebMenuitem
Dim MenuB As WebMenuitem

MainMenu.Append(New WebMenuItem("MainMenu 2"))
MenuA = New WebMenuItem("MainMenu 3")

MenuA.append New WebMenuItem("MenuB 55")
MenuA.append New WebMenuItem("MenuB 77")


MainMenu.Append(MenuA)
MainMenu.Append(New WebMenuItem("MainMenu 4"))



Me.ContextualMenu = MainMenu

This may help:
http://documentation.xojo.com/topics/user_interface/web/menus.html

Well the example shown there works if the main menu has only one item. It doesn’t seem to tell me how to create a hierarchical menu with multiple items.

My guess is that you need to Dim another menuitem, let’s call it MenuWithSub

Dim MenuWithSub As New WebMenuitem

then you add an item to it:

MenuWithSub.Append(New WebMenuItem("MainMenu 2"))

then assign the sub menu to it:

MenuWithSub.Append(MenuB)

then you can have the menu how you want it:

MainMenu.Append(MenuWithSub) MainMenu.Append(New WebMenuItem("MainMenu 3")) MainMenu.Append(New WebMenuItem("MainMenu 4"))

This is not tested, I have no experience with Web apps or menus. This is only from reading that guide. Probably it won’t work.

For my webapps, I went a different route. I used a menu page with treeview control. I used both Jeremie Leroy’s webtreeview control and more recently the GraffitiSuite web treeview. Both work well. It is a completely different paradigm where the menu is used for navigation, and other controls (segmented, tabs, etc.) are used for in-transaction selections. The visual appearence is also much better with the treeview controls. It may or may not suit your application. Other scenarios would be possible, I just settled on this one.

3rd party tools, yes, maybe later…

Alberto,

That sort of does what my original example does - but puts the blanks space on top which holds the submenu. Thanks for trying though.

[quote=440111:@Norman Palardy][code]

Dim MainMenu As New WebMenuitem
Dim MenuA As WebMenuitem
Dim MenuB As WebMenuitem

MainMenu.Append(New WebMenuItem(“MainMenu 2”))
MenuA = New WebMenuItem(“MainMenu 3”)

MenuA.append New WebMenuItem(“MenuB 55”)
MenuA.append New WebMenuItem(“MenuB 77”)

MainMenu.Append(MenuA)
MainMenu.Append(New WebMenuItem(“MainMenu 4”))

Me.ContextualMenu = MainMenu
[/code][/quote]

Didn’t see you sneak that in there Norman. Perfect. Many thanks!

Yeah sorry
I had originally posted then realized the code was wrong & nuked it
Then I just put it back in the same post when I probably should have posted it as a new post

Note New Menuitem(“some text”) creates an item with that text as its label
Appending to that item adds a submenu to it

Thats the trick

[quote=440124:@Peter Greulich]Alberto,

That sort of does what my original example does - but puts the blanks space on top which holds the submenu. Thanks for trying though.[/quote]
This is what my test show following the information I put in my previous post:

Is that not what you want?

The code:

[code]Dim oneDay as new WebMenuItem(“Un Día”)
Dim masMenosUno as new WebMenuItem(“Mañana”)
oneDay.Append(masMenosUno)
masMenosUno = New WebMenuItem(“Ayer”)
oneDay.Append(masMenosUno)

// Create the Dates menu
Dim dateMenu As New WebMenuItem
dateMenu.Append(New WebMenuItem(“Today”))
dateMenu.Append(oneDay)
dateMenu.Append(New WebMenuItem(“Next Week”))
dateMenu.Append(New WebMenuItem(“Next Month”))

// Assign the menu to the dates button
Dim dateButton As WebToolbarMenu
dateButton = WebToolbarMenu(Me.ItemWithName(“DateButton”))
dateButton.Menu = dateMenu[/code]

This is the open event from the sample project in: Examples/Web/Menus/WebToolbarMenu

Edit: I think I’m doing the same that Norman did.

That works too , Alberto. thanks

The only difference that I see from Norman code and mine is that I do this (following the Guide example):

masMenosUno = New WebMenuItem("Ayer") oneDay.Append(masMenosUno)
and following Norman’s example, I can change the code to:

oneDay.Append New WebMenuItem("Ayer")

Thank you Norman for showing another way to code.