Click here to Skip to main content
Click here to Skip to main content

Tree control templates

By , 11 Jun 2001
 

Sample Image - TreeControlTemplates.gif

Introduction

These templates allow CTreeCtrl derived classes programmers to add three basic functionalities to their classes:

  • Iteration of all the items in the control
  • Persistence of the status of the control (when you reload it, it tries to return to its previous state)
  • Expand / Collapse all the items in the tree

Sample Code 1: Deep Iteration

/////////////////////////
// Deep iteration sample

mc_tcTree.Initialize(true);

HTREEITEM hItem= mc_tcTree.GetNext();

while (hItem != NULL)
{
    TRACE(mc_tcTree.GetItemText(hItem) + "\n");

    hItem= mc_tcTree.GetNext();
}

Sample Code 2: Width Iteration

/////////////////////////
// Width iteration sample

mc_tcTree.Initialize(false);

HTREEITEM hItem= mc_tcTree.GetNext();

while (hItem != NULL)
{
    TRACE(mc_tcTree.GetItemText(hItem) + "\n");

    hItem= mc_tcTree.GetNext();
}

Sample Code 3: Expanding All Items

/////////////////////////
// Items expand sample

mc_tcTree.SetRedraw(FALSE);
	
mc_tcTree.ExpandItem();
	
 mc_tcTree.SetRedraw(TRUE);

Sample Code 4: Collapsing All Items

/////////////////////////
// Items collapse sample

mc_tcTree.SetRedraw(FALSE);
	
mc_tcTree.ExpandItem(TVI_ROOT, TVE_COLLAPSE);
	
mc_tcTree.SetRedraw(TRUE);

Sample Code 5: Status Preservation

/////////////////////////
// Status preservation sample

mc_tcTree.SaveStatus();

PopulateTree();

mc_tcTree.RestoreStatus();

That's all folks!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

fjosesen
Web Developer
Spain Spain
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralGood sample!membercen_jin_long7-Aug-08 7:05 
thank you !
 
Optional. This allows you to set your preferences for the discussion boards

JokeNice work. thank you!memberAndy Byron22-Jan-06 16:53 
Smile | :)
GeneralGreat Code !memberWarren Stevens30-Jul-05 9:34 
I have to agree with the comment from "taratata1" below - worked right out of the box, I only had to add two or three lines of code. Nice!
 
This article is certainly a prime example of how code should be written for easy re-use. Well done.
 
Warren
GeneralGreate Articlemembertaratata117-Mar-04 11:07 
I used the code out of the box and worked as expected.
GeneralStress Test problemmemberalan934-Nov-02 6:17 
I am using this very nicely done control to display a 4mb file with 67,000 records.
 
It Loads, displays, and works perfect.
 
However,
 
When exiting the dialog there is about a 3 to 4 second delay before the dialog disappears as if the the control( with all nodes expanded ) needs time to unload before allowing the dialog to exit.
 
?
 
Any thoughts on this?
GeneralThank youmemberAaron Hudon15-Aug-02 11:46 
I dropped your template into my project, and in 2 minutes, it solved my problem of adding many levels of directories to a tree.
 
Thanks you!Smile | :)
Questionhow to change content of nodesmemberVenkata Ramana9-Aug-01 18:54 
Sir,
 
I am working as Associative Consultancy Trainee, in Iridium Interactive,hyderabad,india.
I have downloaded treeview code developed by "Francisco José Sen del Prado".But i don't know how to use it, to my own purpose.Please send information to change content of nodes and child nodes in treeview code.
 
regards,
Venkata Ramana.B
Accociative Consultancy Tainee,
Iridium Interactive Ltd,
iridiuminteractive.com
Hyderabad,
India.

GeneralJust what I neededmemberGeert Delmeiren11-Jun-01 22:22 
The ability to preserve the expanded/collapsed status of the tree items is just what I needed.
I could now add it to my app with less effort.
(I even added two functions to Save and Restore it to/from file).
Thanks a lot.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130617.1 | Last Updated 12 Jun 2001
Article Copyright 2001 by fjosesen
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid