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

Tree control templates

, 11 Jun 2001 CPOL
Rate this:
Please Sign up or sign in to vote.
Three tree control templates to easily operate with CTreeCtrl derived objects
This is an old version of the currently published article.

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)

Share

About the Author


Comments and Discussions


Discussions posted for the Published version of this article. Posting a message here will take you to the publicly available article in order to continue your conversation in public.
 
GeneralGood sample! Pinmembercen_jin_long7-Aug-08 8:05 
JokeNice work. thank you! PinmemberAndy Byron22-Jan-06 17:53 
GeneralGreat Code ! PinmemberWarren Stevens30-Jul-05 10:34 
GeneralGreate Article Pinmembertaratata117-Mar-04 12:07 
GeneralStress Test problem Pinmemberalan934-Nov-02 7:17 
GeneralThank you PinmemberAaron Hudon15-Aug-02 12:46 
Questionhow to change content of nodes PinmemberVenkata Ramana9-Aug-01 19:54 
GeneralJust what I needed PinmemberGeert Delmeiren11-Jun-01 23:22 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411023.1 | Last Updated 12 Jun 2001
Article Copyright 2001 by Francisco José Sen del Prado
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid