2 or more levels in Webtoolbar menu

Is there any trick to make 2 or more submenu level in webtoolbar menu?

Thanks in advance

[quote=192631:@Y Sut]Is there any trick to make 2 or more submenu level in webtoolbar menu?
[/quote]

Here is how to add a submenu (I modified the WebToolBar example):

[code] Dim chartMenu As New WebMenuItem
chartMenu.Append(New WebMenuItem(“Line”))
chartMenu.Append(New WebMenuItem(“Bar”))
chartMenu.Append(New WebMenuItem(“Pie”))
chartMenu.Append(New WebMenuItem("-"))
chartMenu.Append(New WebMenuItem(“3D Line”))
chartMenu.Append(New WebMenuItem(“3D Bar”))
chartMenu.Append(New WebMenuItem(“3D Pie”))

// Add a sub menu
Dim submenu As New WebMenuItem( “SubMenu” )
submenu.Append( New WebMenuItem( “SubMenu Test 1” ) )
submenu.Append( New WebMenuItem( “SubMenu Test 2” ) )
submenu.Append( New WebMenuItem( “SubMenu Test 3” ) )
chartMenu.Append( submenu )[/code]

Hi Michel

Many many thanks for your help :slight_smile: It’s working.

Regards

Hi Michel

sorry, I re-open this post.

Since I want to make dynamic menu items from database, I am facing trouble with your code. I always got the last Append item (SubMenu Test 3) with this edited source, below. Am I missing something?

[code] Dim chartMenu As New WebMenuItem
chartMenu.Append(New WebMenuItem(“3D Line”))
chartMenu.Append(New WebMenuItem(“3D Bar”))
chartMenu.Append(New WebMenuItem(“3D Pie”))

Dim submenu As New WebMenuItem
Dim submenu1 As New WebMenuItem

submenu.Text = “SubMenu”
submenu1 .Text = “SubMenu Test 1”
submenu.Append(submenu1)

submenu1 .Text = “SubMenu Test 2”
submenu.Append(submenu1)

submenu1 .Text = “SubMenu Test 3”
submenu.Append(submenu1)

chartMenu.Append(submenu)[/code]

[quote=192640:@Y Sut]Hi Michel

sorry, I re-open this post.

Since I want to make dynamic menu items from database, I am facing trouble with your code. I always got the last Append item (SubMenu Test 3) with this edited source, below. Am I missing something?[/quote]

I don’t know where you fetched Submenu.Text ? ? ?

Here is an example of one submenu which contains another level. Just modify this and you will be fine :

[code] // Create the chart menu
Dim chartMenu As New WebMenuItem
chartMenu.Append(New WebMenuItem(“Line”))
chartMenu.Append(New WebMenuItem(“Bar”))
chartMenu.Append(New WebMenuItem(“Pie”))
chartMenu.Append(New WebMenuItem("-"))
chartMenu.Append(New WebMenuItem(“3D Line”))
chartMenu.Append(New WebMenuItem(“3D Bar”))
chartMenu.Append(New WebMenuItem(“3D Pie”))

// Add a sub menu
Dim submenu1 As New WebMenuItem( “SubMenu1” )
submenu1.Append( New WebMenuItem( “SubMenu1 Test 1” ) )
submenu1.Append( New WebMenuItem( “SubMenu1 Test 2” ) )
submenu1.Append( New WebMenuItem( “SubMenu1 Test 3” ) )
chartMenu.Append( submenu1 )

// Add a sub menu
Dim SubMenu2 As New WebMenuItem( “SubMenu2” )
SubMenu2.Append( New WebMenuItem( “SubMenu2 Test 1” ) )
SubMenu2.Append( New WebMenuItem( “SubMenu2 Test 2” ) )
SubMenu2.Append( New WebMenuItem( “SubMenu2 Test 3” ) )
submenu1.Append( submenu2 )[/code]

I just make the sample first, to simplify my post. Basically I need the submenu items in SubMenu1 & SubMenu2 are populate from database dynamically, not static like the sample what you gave. So, If I need to add the Submenu items, I just add into database.

Wording “Submenu2 Test 1”, “Submenu2 Test 2”, “Submenu2 Test 3” are from database, as well as wording : “Submenu1 Test 1”, “Submenu1 Test 2” and “Submenu1 Test 3”

Hope can you catch what I mean.

Thank s

[quote=192653:@Y Sut]I just make the sample first, to simplify my post. Basically I need the submenu items in SubMenu1 & SubMenu2 are populate from database dynamically, not static like the sample what you gave. So, If I need to add the Submenu items, I just add into database.

Wording “Submenu2 Test 1”, “Submenu2 Test 2”, “Submenu2 Test 3” are from database, as well as wording : “Submenu1 Test 1”, “Submenu1 Test 2” and “Submenu1 Test 3”

Hope can you catch what I mean.

Thank s[/quote]

You really want to read more about WebMenuItem at http://documentation.xojo.com/index.php/Webmenuitem for details.

I recommend you refer to the WebToolBar example in
Example Projects/Web/Controls/ToolBar/ToolbarExample.xojo_binary_project

I modified the code in the ExampleToolBar Open event.

If you want to populate the menu dynamically, use variables instead of quoted text. An array is probably the most convenient, such as :

// Add a sub menu Dim mymenu() as String mymenu(0) = "SubMenu1 Test 1" mymenu(1) = "SubMenu1 Test 2" mymenu(2) = "SubMenu1 Test 3" Dim submenu1 As New WebMenuItem( "SubMenu1" ) submenu1.Append( New WebMenuItem(mymenu(0) ) ) submenu1.Append( New WebMenuItem(mymenu(1) ) ) submenu1.Append( New WebMenuItem(mymenu(2) ) ) chartMenu.Append( submenu1 )

That way you can simply put the data from the database into mymenu() and affect it to menu items.

Then after you have updated the menuitems, you must assign the modified menu to the Chart button :

// Assign the menu to the chart button Dim chartButton As WebToolbarMenu chartButton = WebToolbarMenu(Me.ItemWithName("ChartsButton")) chartButton.Menu = chartMenu

Got it. Thank you very much :slight_smile: Very appreciate