Results 1 to 4 of 4
  1. #1
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding right-click menu (VB.Net)

    I have a tree view control and I want to add a right-click menu. The items in the menu will change based on the item selected. (I will create multiple context menus and decide at run-time which one to display.)

    I see that .Net calls this type of menu a "context menu" and the VS help text has code showing how to create it and to attach an event to its selection. I can not, however find code to assign it to the treeview. <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15> How does my program know to assign a given context menu to a given control? That's the question <img src=/S/cranky.gif border=0 alt=cranky width=18 height=25>

    In VB or VBA I'd just write code to the right-click event but there is no such thing with the treeview (or other controls it seems). <img src=/S/disappointed.gif border=0 alt=disappointed width=15 height=15>

    Does anyone have code samples that show how to do this? This context menu will have items such as Add, Delete, Copy, etc.

    Thnx, Deb

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding right-click menu (VB.Net)

    Deb,

    Sorry, not sure about .NET...

    but even in VB there's no right click event- it's a MouseDown event, with the key pressed as a parameter.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding right-click menu (VB.Net)

    Many controls in Excel VBA have a right-click event so that's what I'm used to. I ended up finding good stuff in a book by Matthew MacDonald called "User Interfaces in VB.Net:". The way the right-click event works is that after the item is selected (in my case a node in a tree view), an event is fired (no surprise there). At this point one of the arguments in the event code points to a list of events applicable to that control. You query that event structure for the reason why the event was called. One of the reasons available is which key was used to get there. Voila! <img src=/S/bingo.gif border=0 alt=bingo width=15 height=22>

    It take so long to figure out something so simple in .Net sometimes (at least it's hard because I can't just write the code I know how to write, I gotta learn something new *ha*).

    Thnx, Deb

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding right-click menu (VB.Net)

    Deb,
    Open the Toolbox and drag and drop "ContextMenu" to your form.
    Bingo. You'll see a new pane appear (I forget what they call it) with
    a new instance of the contextmenu called contextMenu1.

    Now open the Properties pane for the form. You've now got a ContextMenu
    property. Have at it...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

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