Solved

Programattically create context menu sub items

Posted on 2006-11-01
8
1,295 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
  • 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
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…

831 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