Solved

Programattically create context menu sub items

Posted on 2006-11-01
8
1,312 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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 500 total points
ID: 18015833
Hi wildrobo, did this work for you ?
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

617 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