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. Right Click Menu

Right Click Menu

Scheduled Pinned Locked Moved C#
helpdata-structures
7 Posts 4 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.
  • A Offline
    A Offline
    AhmedMasum
    wrote on last edited by
    #1

    I need help for the following purpose: Suppose I have a tree view and there are various items there. When I right click on a item it will display a menu which contains dynamic options in the menu. [I have tried by context menu strip. For my tree view I have chosen the contextmenustrip1. But problem is when i right click any where on the tree view it shows the menu with static items. But I need when i will right click on any node only at that moment it should appear with some option those are available in a listbox.(The list box is dynamic)]

    OriginalGriffO 1 Reply Last reply
    0
    • A AhmedMasum

      I need help for the following purpose: Suppose I have a tree view and there are various items there. When I right click on a item it will display a menu which contains dynamic options in the menu. [I have tried by context menu strip. For my tree view I have chosen the contextmenustrip1. But problem is when i right click any where on the tree view it shows the menu with static items. But I need when i will right click on any node only at that moment it should appear with some option those are available in a listbox.(The list box is dynamic)]

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Use the ContextMenuStrip.Opening event to modify the content of your menu.

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      A 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Use the ContextMenuStrip.Opening event to modify the content of your menu.

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

        A Offline
        A Offline
        AhmedMasum
        wrote on last edited by
        #3

        Thanks for the help. Now I can make it dynamic. But How can I just do it only for selected node? I only want that when i will click to any node then it should display the menu. Otherwise it should not display the menu if i click any place of the tree view other than any node.

        M M 2 Replies Last reply
        0
        • A AhmedMasum

          Thanks for the help. Now I can make it dynamic. But How can I just do it only for selected node? I only want that when i will click to any node then it should display the menu. Otherwise it should not display the menu if i click any place of the tree view other than any node.

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          You can rebuild the context menu every time you change selected node and just display it OR As suggested use the opening event and rebuild before opeing based on the currently selected node. You may also want to look into the hittest and mousedown to select the node when you right click on it. IIRC the right click does not select the node.

          1 Reply Last reply
          0
          • A AhmedMasum

            Thanks for the help. Now I can make it dynamic. But How can I just do it only for selected node? I only want that when i will click to any node then it should display the menu. Otherwise it should not display the menu if i click any place of the tree view other than any node.

            M Offline
            M Offline
            Muammar
            wrote on last edited by
            #5
                private void yourTreeView\_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
                {
                    ((TreeView)sender).SelectedNode = ((TreeView)sender).GetNodeAt(e.Location);
                }
            

            We will either find a way, or make one!   (\ /)   (- .-) C(''')(''')

            A 1 Reply Last reply
            0
            • M Muammar
                  private void yourTreeView\_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
                  {
                      ((TreeView)sender).SelectedNode = ((TreeView)sender).GetNodeAt(e.Location);
                  }
              

              We will either find a way, or make one!   (\ /)   (- .-) C(''')(''')

              A Offline
              A Offline
              AhmedMasum
              wrote on last edited by
              #6

              Thanks a lot...

              M 1 Reply Last reply
              0
              • A AhmedMasum

                Thanks a lot...

                M Offline
                M Offline
                Muammar
                wrote on last edited by
                #7

                Glad I could help.


                We will either find a way, or make one!   (\ /)   (- .-) C(''')(''')

                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