How to change node color in treeview

Linde

Board Regular
Joined
Dec 27, 2007
Messages
72
Hi all,

Im using Microsoft treeview control, version 6.0 on a form in Excel 2007. I am able to populate the treeview and get it to work.

Now I have in my data a 2 options 'active' and 'not active' status. I want my treeview text color of a node to change to red when a node has the status 'not active' so i can get a visual difference.

I looked in this forum and on the internet but i can't find the solution. Does someone has a solution?

Harm.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Just use the ForeColor.

This is a very simple example that toggles the colour of a node and it's text.
Code:
Private Sub Treeview1_NodeClick(ByVal Node As MSComctlLib.Node)
 
    If Node.Text = "Not Active" Then

        Node.Text = "Active"
        Node.ForeColor = vbRed

    Else
    
        Node.Text = "Not Active"
        Node.ForeColor = vbautomatic

    End If
 
End Sub
 
Upvote 0
Hai Norie,

Thanks for your reply.
I understand the sub but how can I use this while populating the Treeview?

Harm
 
Upvote 0
Hai,

Found the solution:
Code:
Dim Parent As Integer
Parent = 3
Do
If Sheets("PARENTS").Cells(Parent, 42).Value <> "" Then
If Sheets("PARENTS").Cells(Parent, 42).Value = "not active" Then
TV_MAIN.Nodes("P" & Sheets("PARENTS").Cells(Parent, 1).Text).ForeColor = vbRed
TV_MAIN.Nodes("." & Sheets("PARENTS").Cells(Parent, 1).Text).ForeColor = vbRed
Else
test = "." & Sheets("PARENTS").Cells(Parent, 1).Text
TV_MAIN.Nodes("." & Sheets("PARENTS").Cells(Parent, 1).Text).Bold = True
End If
End If
Parent = Parent + 1
Loop Until Sheets("child").Cells(Parent, 1).Value = ""
In this sub I simply loop true the sheet I' am using to populate the treeview TV_MAIN. If the value is "not active" By refering to the nodes key value I change the appaerence of the node. If not "not active" the node is displayed in Bold

Harm
 
Last edited:
Upvote 0
Couldn't you just do this when you add the nodes?
 
Upvote 0
Hello Norie,

Yes, your right it is possible to do this when populating the treeview.

But do you now a way to refer to the newly placed node? For example by using a with structere or else?

Harm.
 
Upvote 0
How are you populating the tree/nodes?

I usually create a reference to each node when it's created/added.

With that reference you can set the various properties of the node.
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,815
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top