Hello.
Could someone give me an example of how to add a new contextmenu item TO another item so it'll be a "submenu"?
lets say i want to add "Hello" to the already existing menu item "Good day".
Thanks! :)
Printable View
Hello.
Could someone give me an example of how to add a new contextmenu item TO another item so it'll be a "submenu"?
lets say i want to add "Hello" to the already existing menu item "Good day".
Thanks! :)
Each menu item has a property named 'MenuItems' or something like that. You add other menu items to that collection and they become subitems and will be displayed automatically.
they havnt got any menu item like that :(
To create submenus, you can add MenuItem objects to the MenuItems property of the parent MenuItem.
VB Code:
'Will get you another cm menu item Me.ContextMenu1.MenuItems.Add("Hello", New EventHandler(AddressOf cmPopup_Click)) 'To add submenus Me.ContextMenu1.MenuItems.Add(cmSubMenu1, New EventHandler(AddressOf cmPopupSub1_Click))
You're using 2005 so I assume that you're using a ContextMenuStrip. It has an Items property, to which you can add ToolStripMenuItems, and each of them has a DropDownItems property, to which you can add more menu items. Here's some basic code to create a two level menu. You'd need to do a bit more work to make it do anything useful but this will give the visual element.Quote:
Originally Posted by Atheist
VB Code:
Me.ContextMenuStrip1.Items.Add("Hello") Me.ContextMenuStrip1.Items.Add("World") Me.ContextMenuStrip1.Items.Add("Goodbye") Dim firstMenuItem As ToolStripMenuItem = DirectCast(Me.ContextMenuStrip1.Items(0), ToolStripMenuItem) firstMenuItem.DropDownItems.Add("Item 1") firstMenuItem.DropDownItems.Add("Item 2") firstMenuItem.DropDownItems.Add("Item 3")
Thanks alot! I used jmcilhinney example and it works fine :)