Click to See Complete Forum and Search --> : Tree view control in VC++ .NET
scorpionguy
May 23rd, 2006, 05:27 PM
--------------------------------------------------------------------------------
I have included a treeview in my windows form in VC++.NET project. I have nearly 10,000 nodes in the tree. I wanted to know whether it is possible to control some of the nodes in this. To be more clear.. I have a button and when i press the button (for example) I want some of the nodes to change its forecolor or something like that. Is this possible?? Please help me ...I m in real trouble and need to solve this problem.
Thanks a lot
ThermoSight
May 23rd, 2006, 05:52 PM
You're in luck, Scorpion!
The TreeView is (at least conceptually) a collection of TreeNodes, and the TreeNode class has a BackColor property.
Thus, I would think that the handler associated with the button to be pressed might call a function which would access the BackColor property of each node whose color you wish to change as a result of the user action. And if you change the BackColor, you may want to think about changin' the ForeColor property as well, in order to keep the text legible.
Ya know, the HELP section of the IDE is an excellent aid in resolving issues such as this. Enter 'TreeView' in the text box and you can see a list of the TreeView members and detailed information on each member. Similarly, you'll want to review TreeNode class as well. This will tell you which method/property you need to use to accomplish the task (and MAN!, that's one heck of a task ..... literally THOUSANDS of nodes? Wow! Better you than me).
However, as I frequently point out, the IDE's HELP section is a reference, not a tutorial. It does point the reader to sample code, but those samples are not generally what I consider a tutorial.
Microsoft's "Visual C++ .NET - Step by Step", and Deitel's "Visual C++ .NET - How to Program" are exceptional tutorials. You might wanna consider droppin' by your local Barnes & Noble or Amazon.com and pickin' up a copy of each.
Best wishes,
bill
scorpionguy
May 23rd, 2006, 06:06 PM
hi thanks for the info bill.. do u atleast know how i can adress a particular node in the tree something like treeView[0] something like that... i m really lost...
ThermoSight
May 23rd, 2006, 07:16 PM
The following comes from the Microsoft's "Step by Step" mentioned in the earlier post.
While it's not doing quite what you wish to do (select multiple nodes, individually), it does show the relationship between the TreeNode, the BackColor and the treeView control. A little bit of Sweat Equity in the IDE 'HELP' section or a tutorial will get you where you want to be.
bill
=================================================
void Form1::DisplayDisks(void){
// get the logical drives
String * drives[] = Directory::GetLogicalDrives();
// add each drive to the treeView after changing the backcolor.
for (int i = 0; i < drives->Count; ++i) {
String *name = dynamic_cast <String *> (drives->Item[i]);
TreeNode *tn = new TreeNode(name);
if (i == 0)
tn->BackColor = Color::FromName(S"AliceBlue");
if (i == 1)
tn->BackColor = Color::FromName(S"Red");
if (i ==2)
tn->BackColor = Color::FromName(S"Green");
if (i > 2)
tn->BackColor = Color::FromName(S"GoldenRod");
treeView1->Nodes->Add(tn);
tn->Nodes->Add(new TreeNode(S"<dummy>"));
}
}// end function 'DisplayDisks'
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.