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

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds