Solved

Changing entire node color of a treeview in VB.NET

Posted on 2014-01-09
1
1,662 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 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