Collapsing a branch


You may have noticed that when you collapse a branch in Explorer and then expand it again later, the effect is that any child branches that were expanded earlier are again expanded. Although, this is mostly helpful, sometimes you want to be able to traverse the outline one level at a time so that you can get the bigger picture before you go on to the detail. We can achieve this programatically by collapsing the main item and then collapsing all its children recursively. Heres the code.
 
// CollapseBranch       - Collapses a branch completely
// hti                  -  Handle of the tree item to collapse
void CTreeCtrlX::CollapseBranch( HTREEITEM hti)
{
        if( ItemHasChildren( hti ) ){
                Expand( hti, TVE_COLLAPSE );
                hti = GetChildItem( hti );
                do{
                        CollapseBranch( hti );
                }while( (hti = GetNextSiblingItem( hti )) != NULL );
        }
}

 



Comments

  • recursive is limited to the size of the stack ???

    Posted by Legacy on 03/15/2002 12:00am

    Originally posted by: D

    but, The number of recursive calls is limited to the size of the stack.
    how to process this problem, if I have many many item?

    Reply
  • Loosing SelectState

    Posted by Legacy on 09/14/1999 12:00am

    Originally posted by: Stephan Heisen

    Hi,

    each time I collaps a branch the Selection Changed Message is send to the parent. How can I prevent that this happens and the items in the branch loose there selectionstate

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Savvy enterprises are discovering that the cloud holds the power to transform IT processes and support business objectives. IT departments can use the cloud to redefine the continuum of development and operations—a process that is becoming known as DevOps. Download the Executive Brief DevOps: Why IT Operations Managers Should Care About the Cloud—prepared by Frost & Sullivan and sponsored by IBM—to learn how IBM SmartCloud Application services provide a robust platform that streamlines …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds