Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to create a contextualized context menu?

How to create a contextualized context menu?

Scheduled Pinned Locked Moved C#
questioncsharpvisual-studiotutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sinosoidal
    wrote on last edited by
    #1

    Hi, I have a TreeView which will be used like the Visual Studio project explorer. In Visual Studio, there are different context menu for different kind of items. How can i do that? As i can see, i can only use one context menu per control. Thx, Nuno

    B J 2 Replies Last reply
    0
    • S sinosoidal

      Hi, I have a TreeView which will be used like the Visual Studio project explorer. In Visual Studio, there are different context menu for different kind of items. How can i do that? As i can see, i can only use one context menu per control. Thx, Nuno

      B Offline
      B Offline
      Bijesh
      wrote on last edited by
      #2

      sinosoidal wrote:

      As i can see, i can only use one context menu per control.

      There is no restriction like that. You can add multiple context menus and set them using the Form.ContextMenu property. Also, you can access the current context menu using the ContextMenu property dynamically add or remove items from it.....

      S 1 Reply Last reply
      0
      • S sinosoidal

        Hi, I have a TreeView which will be used like the Visual Studio project explorer. In Visual Studio, there are different context menu for different kind of items. How can i do that? As i can see, i can only use one context menu per control. Thx, Nuno

        J Offline
        J Offline
        J Dunlap
        wrote on last edited by
        #3

        In a handler for the NodeMouseClick event of the TreeView, remove all the context menu items and add items that are specific for the particular node:

        treeView.NodeMouseClick+=treeView_NodeMouseClick;
        ...
        private void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
        if((e.Button & System.Windows.Forms.MouseButtons.Right)!=0)
        {
        contextMenu.Items.Clear();
        //add some items (e.Node is the node that's being right-clicked)
        contextMenu.Items.Add(e.Node.Name + " 1");
        contextMenu.Items.Add(e.Node.Name + " 2");
        }
        }

        --Justin Microsoft MVP, C#

        C# / Web / VG.net / MyXaml expert currently looking for (telecommute) contract work![^]

        1 Reply Last reply
        0
        • B Bijesh

          sinosoidal wrote:

          As i can see, i can only use one context menu per control.

          There is no restriction like that. You can add multiple context menus and set them using the Form.ContextMenu property. Also, you can access the current context menu using the ContextMenu property dynamically add or remove items from it.....

          S Offline
          S Offline
          sinosoidal
          wrote on last edited by
          #4

          Ahh! I see! Cool Thx, Nuno

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups