Results 1 to 6 of 6

Thread: [RESOLVED] [2005] Context menu :(

  1. #1

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Resolved [RESOLVED] [2005] Context menu :(

    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!
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Context menu :(

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Context menu :(

    they havnt got any menu item like that
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Context menu :(

    To create submenus, you can add MenuItem objects to the MenuItems property of the parent MenuItem.
    VB Code:
    1. 'Will get you another cm menu item
    2. Me.ContextMenu1.MenuItems.Add("Hello", New EventHandler(AddressOf cmPopup_Click))
    3.  
    4. 'To add submenus
    5. Me.ContextMenu1.MenuItems.Add(cmSubMenu1, New EventHandler(AddressOf cmPopupSub1_Click))
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Context menu :(

    Quote Originally Posted by Atheist
    they havnt got any menu item like that
    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.
    VB Code:
    1. Me.ContextMenuStrip1.Items.Add("Hello")
    2.         Me.ContextMenuStrip1.Items.Add("World")
    3.         Me.ContextMenuStrip1.Items.Add("Goodbye")
    4.  
    5.         Dim firstMenuItem As ToolStripMenuItem = DirectCast(Me.ContextMenuStrip1.Items(0), ToolStripMenuItem)
    6.  
    7.         firstMenuItem.DropDownItems.Add("Item 1")
    8.         firstMenuItem.DropDownItems.Add("Item 2")
    9.         firstMenuItem.DropDownItems.Add("Item 3")
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Context menu :(

    Thanks alot! I used jmcilhinney example and it works fine
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width