Solved

Changing entire node color of a treeview in VB.NET

Posted on 2014-01-09
1
1,632 Views
Last Modified: 2014-01-10
I'm working with a large treeview in Visual Studio 2010/Visual Basic.  I'd like to change the whole color of one specific node and everything under the node.  Is there a way I can do this other then adding a line for each child in the node and changing it's forecolor?  Here is an example of one of my nodes.

    TreeView1.Nodes.Add("SAMPLE")  
    TreeView1.Nodes(10).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes.Add(New TreeNode("SAMPLESAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(0).Tag = 68
    TreeView1.Nodes(10).Nodes(0).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(1).Tag = 69
    TreeView1.Nodes(10).Nodes(0).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(2).Tag = 56
    TreeView1.Nodes(10).Nodes(0).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(3).Tag = 70
    TreeView1.Nodes(10).Nodes(0).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(4).Tag = 71
    TreeView1.Nodes(10).Nodes(0).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(5).Tag = 72
    TreeView1.Nodes(10).Nodes(0).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(6).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(6).Nodes(0).Tag = 73
    TreeView1.Nodes(10).Nodes(0).Nodes(6).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(6).Nodes(1).Tag = 74
    TreeView1.Nodes(10).Nodes(0).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(7).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(7).Nodes(0).Tag = 75
    TreeView1.Nodes(10).Nodes(0).Nodes(7).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(7).Nodes(1).Tag = 76
    TreeView1.Nodes(10).Nodes(0).Nodes(7).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(7).Nodes(2).Tag = 77
    TreeView1.Nodes(10).Nodes(0).Nodes(7).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(7).Nodes(3).Tag = 78
    TreeView1.Nodes(10).Nodes(0).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(8).Tag = 79
    TreeView1.Nodes(10).Nodes(0).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(9).Tag = 80
    TreeView1.Nodes(10).Nodes(0).Nodes.Add(New TreeNode("SAMPLE"))
    TreeView1.Nodes(10).Nodes(0).Nodes(10).Tag = 81

Is there a way I can get at node 10 and set every ForeColor under it in one line of code?

Thanks.
0
Comment
Question by:pmac38CDS
1 Comment
 
LVL 11

Accepted Solution

by:
MajorBigDeal earned 500 total points
ID: 39769585
   
ColorNodes(TreeView1.Nodes(10))

    Private Sub ColorNodes(n As TreeNode)
        n.ForeColor = Color.Red
        For Each subNode In n.Nodes
            ColorNodes(subNode)
        Next
    End Sub

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question