TreeView text - possible to make it bold?

X

Xenomorph

I have a program where you click an item on the TreeView on the left, and
then work with whatever pops up on the right.

There are many entries on the TreeView, and when you click something on the
right, the item on the TreeView is no longer highlighted, making it hard to
keep track of which item you clicked on the TreeView.

I want the item clicked on in the TreeView to turn BOLD, or get underlined,
or change color or something. Just so when you start working on the right
side of the window, whatever TreeView item you clicked on is still
highlighted in some way.

Anyone know how to do this?
 
B

Bill McCarthy

Hi,

You can turn the HideSelection property to False and it should remain
highlighted when the treeview looses focus.

Regards,

Bill.
 
X

Xenomorph

That does keep it highlighted, yes. It gives the item a grey background
which looks fine with the standard Windows color scheme ("Classic" view on
XP and Vista), but on the default color view of XP and Vista, its a little
hard to notice. Thats one reason why I was hoping to make the text bold or
underlined when clicked.

Thank you.
 
B

Bill McCarthy

Hi,

Okay so you could handle the AfterSelect event, then get e.Node ands set
it's ForeColor, BackColor or NodeFont etc.
You'd probably need to keep a reference to the previously selected node so
as to reset it, e.g:

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Static previousNode as TreeNode
If previousNode IsNot Nothing Then
'reset the previous Node's font and color properties here
End If
previousNode = e.Node
With previousNode
.NodeFont = someFont
.BackColor = ......
End With
End Sub
 
X

Xenomorph

After the first "If previousNode IsNot Nothing Then", I had to add this
section:

With previousNode
' my code here
End With

....but other than that, it worked!!! Thank you!

When I click something on the TreeView, the text is underlined, so even when
it's not highlighted, you can still tell which one is clicked on.
 

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