Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Programattically create context menu sub items

Posted on 2006-11-01
8
Medium Priority
?
1,319 Views
Last Modified: 2012-08-13
I would like to create a context menu that has "Variable", "Static"
then I want to create sub items programatically?  how would I do that?

This is what i want to acheive

Variable
    x
    y
    z
Static
    q
    w  
    e

but I want to add xyz dynamically.

Thanks
0
Comment
Question by:wildrobo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
8 Comments
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 17852869
           Dim newMenu As MenuItem

            newMenu = New MenuItem("x")
            ContextMenu1.MenuItems(0).MenuItems.Add(newMenu)
            newMenu = New MenuItem("y")
            ContextMenu1.MenuItems(0).MenuItems.Add(newMenu)
            newMenu = New MenuItem("z")
            ContextMenu1.MenuItems(0).MenuItems.Add(newMenu)
0
 

Author Comment

by:wildrobo
ID: 17853251
Thanks I tried it but I get

'MenuItems' is not a member of 'System.Windows.Forms.ContextMenuStrip'

Any thoughts?
0
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 17853580
Ahhh, you're using VS2005.  The ContextMenuStrip replaced VS2003's ContextMenu.  I don't personally use VS2005, so hopefully someone else can help!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:wildrobo
ID: 17853795
Thanks, Sorry I should have clarified.  I am just finding out now that the contectmenustip is what to use in vs2005, but not finding much help.  Thank you for your time.
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17870696
This is how you do it in vs2005 ....

you create the sub item and assign it to the main menu item ... then add it to your ContextMenuStrip !

        Dim contextMenuStrip As ContextMenuStrip
        Dim firstItem As ToolStripMenuItem
        Dim subItem As ToolStripMenuItem

        contextMenuStrip = New ContextMenuStrip()
        firstItem = New ToolStripMenuItem("level one")
        subItem = New ToolStripMenuItem("level two")

        firstItem.DropDownItems.Add(subItem)
        contextMenuStrip.Items.Add(firstItem)

the only documentation is on Mars.
cheers ..
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17870975
oh, and if you want to add an event handler ... which I guess you will !

        Dim contextMenuStrip As ContextMenuStrip
        Dim firstItem As ToolStripMenuItem
        Dim subItem As ToolStripMenuItem

        contextMenuStrip = New ContextMenuStrip()
        firstItem = New ToolStripMenuItem("level one")
        subItem = New ToolStripMenuItem("level two")
        AddHandler SubItem.Click, AddressOf BorderThicknessMinusSprite

        firstItem.DropDownItems.Add(subItem)
        contextMenuStrip.Items.Add(firstItem)

Theres no intellisense for the SubItem.Click .....
0
 
LVL 10

Accepted Solution

by:
Kinger247 earned 2000 total points
ID: 18015833
Hi wildrobo, did this work for you ?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question