Click here to Skip to main content
Licence CPOL
First Posted 5 Jun 2001
Views 90,914
Bookmarked 32 times

Tree control templates

By | 11 Jun 2001 | Article
Three tree control templates to easily operate with CTreeCtrl derived objects

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



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. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGood sample! Pinmembercen_jin_long7:05 7 Aug '08  
JokeNice work. thank you! PinmemberAndy Byron16:53 22 Jan '06  
GeneralGreat Code ! PinmemberWarren Stevens9:34 30 Jul '05  
GeneralGreate Article Pinmembertaratata111:07 17 Mar '04  
GeneralStress Test problem Pinmemberalan936:17 4 Nov '02  
GeneralThank you PinmemberAaron Hudon11:46 15 Aug '02  
Questionhow to change content of nodes PinmemberVenkata Ramana18:54 9 Aug '01  
GeneralJust what I needed PinmemberGeert Delmeiren22:22 11 Jun '01  

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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