Solved

Programattically create context menu sub items

Posted on 2006-11-01
8
1,302 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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