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
Member
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! Pinmembercen_jin_long7 Aug '08 - 7:05 
JokeNice work. thank you! PinmemberAndy Byron22 Jan '06 - 16:53 
GeneralGreat Code ! PinmemberWarren Stevens30 Jul '05 - 9:34 
GeneralGreate Article Pinmembertaratata117 Mar '04 - 11:07 
GeneralStress Test problem Pinmemberalan934 Nov '02 - 6:17 
GeneralThank you PinmemberAaron Hudon15 Aug '02 - 11:46 
Questionhow to change content of nodes PinmemberVenkata Ramana9 Aug '01 - 18:54 
GeneralJust what I needed PinmemberGeert Delmeiren11 Jun '01 - 22:22 

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.130516.1 | Last Updated 12 Jun 2001
Article Copyright 2001 by fjosesen
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid