What’s the easiest way to delete all items in a submenu without changing the menu?
close them one by one in reverse order
That brings up three questions:
- How do I find out how many there are?
- Are they numbered origin zero or one?
- A code example would be appreciated.
Thanks
Sorry remove them and do nothing with them
http://documentation.xojo.com/index.php/MenuItem
http://documentation.xojo.com/index.php/MenuItem.Count
// if m is the menu item that has child items attached to it
for i as integer = m.Count-1 downto 0
m.child(i).Remove
next
MenuBars & menu items are really quite simple
A MenuBar is a instance of the MenuBar class - it has “children” that represent the top level menus (File, Edit, etc)
Each of those children is a menu item
Each menu item can have children - and all of those children are menu items
[code]MenuBar (name = MenuBar1)
Menuitem (name = File, Text = “File” and other properties to make the FILE menu)
MenuItem (name = FileOpen , Text = “Open” and other properties you want to make the “Open” menu item)
Menuitem (name = Edit and other properties to make the EDIT menu)
MenuItem (name = EditCut, Text = “Cut” and other properties you want to make the “Cut” menu item)
[/code]
So you can use a for next loop to look for the “File” top level menu item
for i as integer = 0 to MenuBar1.Count-1
if menuBar1.child(i).Name = "File" then msgbox "Found the file menu"
next
Or you can look for a specific item in a specific menu (say the Cut item in the Edit Menu)
for i as integer = 0 to MenuBar1.Count-1
if menuBar1.child(i).Name = "Edit" then
dim editMenu as menuItem = menuBar1.child(i)
msgbox "Found the Edit menu"
for j as integer = 0 to editMenu.Count - 1
if editMenu.child(i).Name = "Cut" then msgbox "Found the Edit > Cut menu item"
next
end if
next
and so on as far as you want to go with this.