Solved

Changing entire node color of a treeview in VB.NET

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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 …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now