Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I click on a node in the TreeView it of course becomes highlighted. But when I switch the focus to a button, or a textbox or anything it is no longer highlighted. I'm pretty sure it's still "selected" but not visually. Is there a way to make it stay visually selected?

Thanks!
Posted

What you basically need to do is color the background of the selected node when the control loses focus.
You could try the following:
VB
Private Sub TreeView1_LostFocus(sender As Object, e As System.EventArgs) Handles TreeView1.LostFocus
    ' When your TreeView loses focus get the currently selected node and
    ' change the backcolor of the node to something that indicates inactivity.
    TreeView1.SelectedNode.BackColor = SystemColors.InactiveCaption
End Sub

Private Sub TreeView1_GotFocus(sender As Object, e As System.EventArgs) Handles TreeView1.GotFocus
    ' When the TreeView receives focus again the last selected nodes backcolor needs to be reset.
    TreeView1.SelectedNode.BackColor = Nothing 
End Sub
Hope it helps :)
 
Share this answer
 
v2
When you lose focus from the app it doesn't seem to trigger the treeview1_lostFocus.

I noticed when taking a screen shot with a third party tool.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900