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

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

Francisco José Sen del Prado
Software Developer (Senior)
Spain Spain
I started programming in Basic language when I was 14 years old. The second programming language I learned was Z80 assembler. I've been programming with C++ for the last 20 years. I attended the 2012 C++ Now event in Aspen and it was the most exciting experience I've lived in my professional life. I met a lot of brilliant C++ minds and I have very good memories from that trip.

Comments and Discussions

GeneralGood sample! Pinmembercen_jin_long7-Aug-08 8:05 
JokeNice work. thank you! PinmemberAndy Byron22-Jan-06 17:53 
Smile | :)
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
Web03 | 2.8.150327.1 | Last Updated 12 Jun 2001
Article Copyright 2001 by Francisco José Sen del Prado
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid