[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Changing entire node color of a treeview in VB.NET

Posted on 2014-01-09
1
Medium Priority
?
1,803 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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

650 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