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. Treeview question

Treeview question

Scheduled Pinned Locked Moved C#
questiondata-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
    Aaron Schaefer
    wrote on last edited by
    #1

    Hello All, I have an app which has a treeview, and I would like to perform a unique action when the user double clicks a leaf node of the tree. I handled the double click event, but this doesn't tell me much. How do I get to the actual tree node (if any) that the user double clicked on? Thanks

    L 1 Reply Last reply
    0
    • A Aaron Schaefer

      Hello All, I have an app which has a treeview, and I would like to perform a unique action when the user double clicks a leaf node of the tree. I handled the double click event, but this doesn't tell me much. How do I get to the actual tree node (if any) that the user double clicked on? Thanks

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      SelectedNode xacc-ide 0.0.12 now with C#, MSIL, C, XML, ASP.NET and HLSL coloring - Screenshots

      A 1 Reply Last reply
      0
      • L leppie

        SelectedNode xacc-ide 0.0.12 now with C#, MSIL, C, XML, ASP.NET and HLSL coloring - Screenshots

        A Offline
        A Offline
        Aaron Schaefer
        wrote on last edited by
        #3

        Thanks. But, the problem that I am having is that the dobule click handler is called anytime the user double clicks anywahere in the tree, whether or not the user actually double clicked on a tree node. If I click off in the empty space of the control, the handler is called. The selected node property has a node in it, but I don't have any way to know if that node was actually double clicked. Aaron

        N L 2 Replies Last reply
        0
        • A Aaron Schaefer

          Thanks. But, the problem that I am having is that the dobule click handler is called anytime the user double clicks anywahere in the tree, whether or not the user actually double clicked on a tree node. If I click off in the empty space of the control, the handler is called. The selected node property has a node in it, but I don't have any way to know if that node was actually double clicked. Aaron

          N Offline
          N Offline
          Nick Parker
          wrote on last edited by
          #4

          Try handling the AfterSelect event instead. You can do something like the following:

          	private void treeView1\_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
          	{
          		TreeNode node = e.Node as TreeNode;
          		if(node != null)
          		{	
          			MessageBox.Show(node.Text);
          		}
          	}
          

          - Nick Parker Microsoft MVP - Visual C#
          My Blog | My Articles

          A 1 Reply Last reply
          0
          • A Aaron Schaefer

            Thanks. But, the problem that I am having is that the dobule click handler is called anytime the user double clicks anywahere in the tree, whether or not the user actually double clicked on a tree node. If I click off in the empty space of the control, the handler is called. The selected node property has a node in it, but I don't have any way to know if that node was actually double clicked. Aaron

            L Offline
            L Offline
            Luis Alonso Ramos
            wrote on last edited by
            #5

            The GetNodeAt[^] member will tell you the node at a specific point location. But looking at the docs for DoubleClick[^] event, the TreeView is not supposed to raise a Click or DoubleClick event if the click is not over a node (see below the table before the example.) -- LuisR


            Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

            A 1 Reply Last reply
            0
            • L Luis Alonso Ramos

              The GetNodeAt[^] member will tell you the node at a specific point location. But looking at the docs for DoubleClick[^] event, the TreeView is not supposed to raise a Click or DoubleClick event if the click is not over a node (see below the table before the example.) -- LuisR


              Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

              A Offline
              A Offline
              Aaron Schaefer
              wrote on last edited by
              #6

              Well, the documentation says that it will not, but if I set a breakpoint in the handler for the double click event, and double click somewhere off in the margin of the control (not over a node), the handler is called. The double click event does not contain any mouse location info to use with GetNodeAt. I suppose maybe I could also have a handler for MouseDown, or MouseUp, and save these coordinates for use in the handler for double click, but that seems kind of ugly.

              1 Reply Last reply
              0
              • N Nick Parker

                Try handling the AfterSelect event instead. You can do something like the following:

                	private void treeView1\_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
                	{
                		TreeNode node = e.Node as TreeNode;
                		if(node != null)
                		{	
                			MessageBox.Show(node.Text);
                		}
                	}
                

                - Nick Parker Microsoft MVP - Visual C#
                My Blog | My Articles

                A Offline
                A Offline
                Aaron Schaefer
                wrote on last edited by
                #7

                Yes, but this will be called if I single click the tree node, won't it? Basically, I need to perform two different actions if the user double clicks a tree node, and if they simply select it (by moving the keyboard, or clicking on it with the mouse). If the double click event args had some more info in them, like mouse coordinates, it would help me figure out if the user actually double clicked a node, or off in space. My only other thought is to also handle mouse down events, save the corrdinates from these, and use them in the handler to doube click to figure out where the double click happened. This seems pretty messy, surely, there's a cleaner way to do this?

                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