Solved

Changing entire node color of a treeview in VB.NET

Posted on 2014-01-09
1
1,604 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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