How to highlight a Treeview node so that it remains highlighted when the Treeview loses focus

LeighWardle
LeighWardle used Ask the Experts™
on
Hi Experts,

How can I highlight a Treeview node so that the highlight does not dim when the Treeview loses focus?

My VB6 project is attached.
If you run this you will see the highlight on "one".
But if you click the button labelled "click me so Treeview loses focus", the highlight on "one" dims.

Regards,
Leigh
v13.1.5.zip
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
I don't believe that's possible.
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You could however use an icon to note that it's selected.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Set the HideSelection() property of the TreeView to False.
Commented:
To keep the treeview node highlighted we can use the "LockWindowUpdate" function .
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long

Open in new window

Modifications :
1)
In the Sub "tvTreeView_NodeClick" (in frmTreeview)
add this code (these three lines should be the first lines):

Private Sub tvTreeView_NodeClick(ByVal Node As MSComctlLib.Node)
    Call LockWindowUpdate(0)
    DoEvents
    Call LockWindowUpdate(tvTreeView.hwnd)

2)
In the Sub "Form_Load()" in frmTreeview :

instead ...
    tvTreeView.Nodes.Add , , "two", "two"

... it should be :
    tvTreeView.Nodes.Add , , "two", "two"
    tvTreeView.Nodes(1).Selected = True
test.zip

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial