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

TreeView

Scheduled Pinned Locked Moved C#
csharpwinformsquestion
9 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.
  • L Offline
    L Offline
    Luther Baker
    wrote on last edited by
    #1

    I'm fairly new to C# and WinForms programming. How does one programmatically "select" a node in a TreeView. IE: the user clicks a button which spawns a child process, the output of which is displayed in a TextBox. Each time the user clicks that button, a new process is kicked off and I attach a new node to the TreeView to represent said process. If the user clicks on any given node, that node's associated process output TextBox is brought to the foreground - whre you can watch the output. Adding the node to the TreeView is straightforward, but hilighting it or "selecting" it programmatically is not so easy. Suggestions? -Luther

    T 1 Reply Last reply
    0
    • L Luther Baker

      I'm fairly new to C# and WinForms programming. How does one programmatically "select" a node in a TreeView. IE: the user clicks a button which spawns a child process, the output of which is displayed in a TextBox. Each time the user clicks that button, a new process is kicked off and I attach a new node to the TreeView to represent said process. If the user clicks on any given node, that node's associated process output TextBox is brought to the foreground - whre you can watch the output. Adding the node to the TreeView is straightforward, but hilighting it or "selecting" it programmatically is not so easy. Suggestions? -Luther

      T Offline
      T Offline
      Tristan Rhodes
      wrote on last edited by
      #2

      Isn't there a: treeview.setActiveNode(node) method? if you create the node as a variable first, then add it, and set the variable to the active node, it should do it. I had this problem with seting the active node of a tree view when it first gets control. Cata

      H 1 Reply Last reply
      0
      • T Tristan Rhodes

        Isn't there a: treeview.setActiveNode(node) method? if you create the node as a variable first, then add it, and set the variable to the active node, it should do it. I had this problem with seting the active node of a tree view when it first gets control. Cata

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        Active and Selected are two completely different things. Active just means that the node has the focus, such as what it gains when you right-click the node. Selected means that the node has been left-clicked at some point. To select a node programmatically, just use the following:

        treeview.SelectedNode = someNode;

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        T L 2 Replies Last reply
        0
        • H Heath Stewart

          Active and Selected are two completely different things. Active just means that the node has the focus, such as what it gains when you right-click the node. Selected means that the node has been left-clicked at some point. To select a node programmatically, just use the following:

          treeview.SelectedNode = someNode;

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          T Offline
          T Offline
          Tristan Rhodes
          wrote on last edited by
          #4

          That's what I was looking for.

          L 1 Reply Last reply
          0
          • T Tristan Rhodes

            That's what I was looking for.

            L Offline
            L Offline
            Luther Baker
            wrote on last edited by
            #5

            The obvious escaped me. Thank you both. -LutherB

            1 Reply Last reply
            0
            • H Heath Stewart

              Active and Selected are two completely different things. Active just means that the node has the focus, such as what it gains when you right-click the node. Selected means that the node has been left-clicked at some point. To select a node programmatically, just use the following:

              treeview.SelectedNode = someNode;

              -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

              L Offline
              L Offline
              Luther Baker
              wrote on last edited by
              #6

              After doing this - indeed the "selected" image appears to the left of the tree node (from the ImageList index used when creating the node) but, the actual text of the node is not "highlighted. IE: the folder opens, but the folder name is not highlighted. This is even more obvious when working with a ListView. I've selected a particular ListViewItem, but no rectangular, reverse color block around the text of the item appears onscreen. Maybe I am doing something wrong - or missing something? Without the highlighted text, its not really obvious which element has been selected. Thanks, -Luther

              H 1 Reply Last reply
              0
              • L Luther Baker

                After doing this - indeed the "selected" image appears to the left of the tree node (from the ImageList index used when creating the node) but, the actual text of the node is not "highlighted. IE: the folder opens, but the folder name is not highlighted. This is even more obvious when working with a ListView. I've selected a particular ListViewItem, but no rectangular, reverse color block around the text of the item appears onscreen. Maybe I am doing something wrong - or missing something? Without the highlighted text, its not really obvious which element has been selected. Thanks, -Luther

                H Offline
                H Offline
                Heath Stewart
                wrote on last edited by
                #7

                Out of curiousity, does the rectangular marquee (the dotted lines) around the text appear? If so, the TreeView no longer seems to have the focus. Set TreeView.HideSelection to false and see if the rectangular selection region is at least gray (or whatever the default system color for inactive selected text is).

                -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                L 2 Replies Last reply
                0
                • H Heath Stewart

                  Out of curiousity, does the rectangular marquee (the dotted lines) around the text appear? If so, the TreeView no longer seems to have the focus. Set TreeView.HideSelection to false and see if the rectangular selection region is at least gray (or whatever the default system color for inactive selected text is).

                  -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                  L Offline
                  L Offline
                  Luther Baker
                  wrote on last edited by
                  #8

                  Excellent - a grey "highlight" block appears around the text now - for both the visible ListView and TreeView. Its not the normal (per my theme) "blue" highlight, but its a clear indication to the user - which is my real goal. Thanks Again, -LutherB

                  1 Reply Last reply
                  0
                  • H Heath Stewart

                    Out of curiousity, does the rectangular marquee (the dotted lines) around the text appear? If so, the TreeView no longer seems to have the focus. Set TreeView.HideSelection to false and see if the rectangular selection region is at least gray (or whatever the default system color for inactive selected text is).

                    -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                    L Offline
                    L Offline
                    Luther Baker
                    wrote on last edited by
                    #9

                    Aha ... I understand now. Makes perfect sense. The issue of "focus" that is. One more line, TreeView.focus() does the final trick. Thanks, -Luther

                    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