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

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • You probably have several goals for your patient portal of choice. Is "community" one of them? With a bevy of vendors offering portal solutions, it can be challenging for a hospital to know where to start. Fortunately, YourCareCommunity helps ease the decision-making process. Read this white paper to learn more. "3 Ways Clinicians can Leverage a Patient Portal to Craft a Healthcare Community" is a published document owned by www.medhost.com

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds