PDA

Click to See Complete Forum and Search --> : Mergin Menus


hbandarra
Nov 21st, 2002, 04:13 AM
When I Merge two main menus, the names are not overriden as I would like to be:

for example:


menuA:
File Edit Help
a1 b1 c1
a2 b2 c2

menuB:
Help
c3

menuA.MergeMenu(menuB) should be:
File Edit Help
a1 b1 c1
a2 b2 c2
c3

but instead, I get:
File Edit Help Help
a1 b1 c1 c3
a2 b2 c2


Why is that? How do I get the desired behaviour?

Thx!

cim3
Nov 21st, 2002, 05:04 AM
This works

Dim a1 As New MenuItem()
Dim a2 As New MenuItem()
Dim a3 As New MenuItem()
Dim b1 As New MenuItem()
Dim b2 As New MenuItem()

a1.Text = "Edit"
a2.Text = "Paste"
a3.Text = "Copy"

b1.Text = "Edit"
b2.Text = "Cut"

a1.MenuItems.Add(a2)
a1.MenuItems.Add(a3)
b1.MenuItems.Add(b2)

a1.MergeMenu(b1)

MainMenu1.MenuItems.Add(a1)
'MainMenu1.MenuItems.Add(b1)

hbandarra
Nov 21st, 2002, 05:39 AM
Thanks, cim3!

Based on your example, I've written the following working code:


Dim localMainMenu As MainMenu = GetLocalMainMenu()
Dim remoteMainMenu As MainMenu = GetRemoteMainMenu()

Dim remoteMenuItem As MenuItem
For Each remoteMenuItem In remoteMainMenu.MenuItems
Dim localMenuItem As MenuItem
Dim localFound As Boolean = False
For Each localMenuItem In localMainMenu.MenuItems
If localMenuItem.Text = remoteMenuItem.Text Then
localMenuItem.MergeMenu(remoteMenuItem)
localFound = True
Exit For
End If
Next
If localFound = False Then
localMainMenu.MenuItems.Add(remoteMenuItem)
End If
Next

But, as you can see, this solution ignores any ordering or merging type defined by the menu items.
Of course I could do it my self, but was'n it supposed to work wright just by doing:

localMainMenu.MergeMenu(remoteMainMenu)


?

Thx!