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: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds