Click here to Skip to main content
11,921,138 members (53,784 online)
Click here to Skip to main content
Add your own
alternative version


35 bookmarked

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


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


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


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


Sample Code 4: Collapsing All Items

// Items collapse sample

mc_tcTree.ExpandItem(TVI_ROOT, TVE_COLLAPSE);

Sample Code 5: Status Preservation

// Status preservation sample




That's all folks!


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


About the Author

You may also be interested in...

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! Pin
cen_jin_long7-Aug-08 8:05
membercen_jin_long7-Aug-08 8:05 
JokeNice work. thank you! Pin
Andy Byron22-Jan-06 17:53
memberAndy Byron22-Jan-06 17:53 
GeneralGreat Code ! Pin
Warren Stevens30-Jul-05 10:34
memberWarren Stevens30-Jul-05 10:34 
GeneralGreate Article Pin
taratata117-Mar-04 12:07
membertaratata117-Mar-04 12:07 
GeneralStress Test problem Pin
alan934-Nov-02 7:17
memberalan934-Nov-02 7:17 
GeneralThank you Pin
Aaron Hudon15-Aug-02 12:46
memberAaron Hudon15-Aug-02 12:46 
Questionhow to change content of nodes Pin
Venkata Ramana9-Aug-01 19:54
memberVenkata Ramana9-Aug-01 19:54 
GeneralJust what I needed Pin
Geert Delmeiren11-Jun-01 23:22
memberGeert Delmeiren11-Jun-01 23:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web01 | 2.8.151120.1 | Last Updated 12 Jun 2001
Article Copyright 2001 by Francisco José Sen del Prado
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid