TreeView
-
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
-
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
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
-
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
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-----
-
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-----
That's what I was looking for.
-
That's what I was looking for.
The obvious escaped me. Thank you both. -LutherB
-
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-----
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
-
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
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. SetTreeView.HideSelection
tofalse
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-----
-
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. SetTreeView.HideSelection
tofalse
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-----
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
-
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. SetTreeView.HideSelection
tofalse
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-----
Aha ... I understand now. Makes perfect sense. The issue of "focus" that is. One more line, TreeView.focus() does the final trick. Thanks, -Luther