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