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. Managed C++/CLI
  4. TreeView control node selection

TreeView control node selection

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++visual-studio
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.
  • B Offline
    B Offline
    BuckBrown
    wrote on last edited by
    #1

    Hi, I'm using Visual Studio 2005 C++/CLI. I have a TreeView Control that displays a few nodes with some sub-nodes in each. I have written the application so if I right click on a sub-node I get a ContextMenuStrip where I can select "MenuItem". If I left click on a sub-node FIRST (thus selecting the node) then right click to select "MenuItem", I can then use... TreeNode^ selectedNode = this->treeViewInstruments->SelectedNode; ...to get a copy of the selected node. However, if I DO NOT left click on the sub-node first and simply right click on it and then select "MenuItem" the above line of code returns an undefined value. I added code to respond to the mouse right click on a node but I can't seem to set the node as selected. I just want to be able to "set the node I just right clicked on to the selected node". Thanks Buck

    N L 2 Replies Last reply
    0
    • B BuckBrown

      Hi, I'm using Visual Studio 2005 C++/CLI. I have a TreeView Control that displays a few nodes with some sub-nodes in each. I have written the application so if I right click on a sub-node I get a ContextMenuStrip where I can select "MenuItem". If I left click on a sub-node FIRST (thus selecting the node) then right click to select "MenuItem", I can then use... TreeNode^ selectedNode = this->treeViewInstruments->SelectedNode; ...to get a copy of the selected node. However, if I DO NOT left click on the sub-node first and simply right click on it and then select "MenuItem" the above line of code returns an undefined value. I added code to respond to the mouse right click on a node but I can't seem to set the node as selected. I just want to be able to "set the node I just right clicked on to the selected node". Thanks Buck

      N Offline
      N Offline
      Nishad S
      wrote on last edited by
      #2

      Sorry, I didn't get you... Are you trying to select a tree item using the right click?

      - NS - [ODBaseBtn]

      1 Reply Last reply
      0
      • B BuckBrown

        Hi, I'm using Visual Studio 2005 C++/CLI. I have a TreeView Control that displays a few nodes with some sub-nodes in each. I have written the application so if I right click on a sub-node I get a ContextMenuStrip where I can select "MenuItem". If I left click on a sub-node FIRST (thus selecting the node) then right click to select "MenuItem", I can then use... TreeNode^ selectedNode = this->treeViewInstruments->SelectedNode; ...to get a copy of the selected node. However, if I DO NOT left click on the sub-node first and simply right click on it and then select "MenuItem" the above line of code returns an undefined value. I added code to respond to the mouse right click on a node but I can't seem to set the node as selected. I just want to be able to "set the node I just right clicked on to the selected node". Thanks Buck

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        Hey Buck, I have not got around to doing this with the .NET TreeView yet but I had to deal with it in MFC years ago so it should translate. In my OnContextMenu handler I used the tree control HitTest() to discover the node that was clicked on. I see in the BCL TreeView documentation it has a HitTest() method. I don't know if translating the point would still apply in the .NET environment in that it might already be done.

        void CEdTree::OnContextMenu(CWnd*, CPoint point)
        {
                CPoint pt(point);
                ScreenToClient(&pt);
                _nmRClickItem = tree().HitTest(pt);

        B 1 Reply Last reply
        0
        • L led mike

          Hey Buck, I have not got around to doing this with the .NET TreeView yet but I had to deal with it in MFC years ago so it should translate. In my OnContextMenu handler I used the tree control HitTest() to discover the node that was clicked on. I see in the BCL TreeView documentation it has a HitTest() method. I don't know if translating the point would still apply in the .NET environment in that it might already be done.

          void CEdTree::OnContextMenu(CWnd*, CPoint point)
          {
                  CPoint pt(point);
                  ScreenToClient(&pt);
                  _nmRClickItem = tree().HitTest(pt);

          B Offline
          B Offline
          BuckBrown
          wrote on last edited by
          #4

          Yes, I looked up the HitTest() doc and implemented it and it worked wonderfully. Thanks Mike, Buck

          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