TreeView SelectedNodeStyle and HideSelection Properties

L

Loren

I’m having a couple of problems using the TreeView control on a windows form.
I feel as if I’m missing something very obvious, but I not seeing it! Any
suggestions would be appreciated.

1. I’d like to change the background color of the selected treeview node.
To do this it looks as if I need to change the treeview’s SelectedNodeStyle
property. MSDN states that “this property is read-only; however, you can set
the properties of the TreeNodeStyle object it returns.†So my first step is
to retrieve the current SelectedNodeStyle so I can modify it. I’m trying to
do that with the following code:

Dim myTreeView As TreeView
Dim currentSelectedNodeStyle As TreeNodeStyle
currentSelectedNodeStyle = myTreeView.SelectedNodeStyle

However the above code results in the following two errors:
Error 1 Type 'TreeNodeStyle' is not defined.
Error 2 'SelectedNodeStyle' is not a member of System.Windows.Forms.TreeView'.

2. When my treeview control looses focus I would like to maintain the
highlighting of the selected node. It appears that this can be accomplished
by setting the following property:

myTreeView.HideSelection = False

However, changing the value of this property either via the treeview’s
property page or programmatically has no effect on the highlighting of the
selected node when myTreeView loses focus; the highlighting disappears if
this property is either True or False.
 
A

Armin Zingler

Loren said:
I’m having a couple of problems using the TreeView control on a
windows form. I feel as if I’m missing something very obvious, but I
not seeing it! Any suggestions would be appreciated.

1. I’d like to change the background color of the selected treeview
node. To do this it looks as if I need to change the treeview’s
SelectedNodeStyle property. MSDN states that “this property is
read-only; however, you can set the properties of the TreeNodeStyle
object it returns.†So my first step is to retrieve the current
SelectedNodeStyle so I can modify it. I’m trying to do that with the
following code:

Dim myTreeView As TreeView
Dim currentSelectedNodeStyle As TreeNodeStyle
currentSelectedNodeStyle = myTreeView.SelectedNodeStyle

However the above code results in the following two errors:
Error 1 Type 'TreeNodeStyle' is not defined.
Error 2 'SelectedNodeStyle' is not a member of
System.Windows.Forms.TreeView'.


If it is a Winforms app, there is no SelectedNodeStyle property. You
probably mixed up the two controls because there is also a Treeview
control for Web apps.

2. When my treeview control looses focus I would like to maintain
the highlighting of the selected node. It appears that this can be
accomplished by setting the following property:

myTreeView.HideSelection = False

However, changing the value of this property either via the
treeview’s property page or programmatically has no effect on the
highlighting of the selected node when myTreeView loses focus; the
highlighting disappears if this property is either True or False.


I can't answer this one. Maybe it's the color setting chosen in control
panel. Usually, it should work.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top