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: April 22, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Database professionals — whether developers or DBAs — can often save valuable time by learning to get the most from their new or existing productivity tools. Whether you're responsible for managing database projects, performing database health checks and reporting, analyzing code, or measuring software engineering metrics, it's likely you're not taking advantage of some of the lesser-known features of Toad from Dell. Attend this live …

  • Ever-increasing workloads and the challenge of containing costs leave companies conflicted by the need for increased processing capacity while limiting physical expansion. Migration to HP's new generation of increased-density rack-and-blade servers can address growing demands for compute capacity while reducing costly sprawl. Sponsored by: HP and Intel® Xeon® processors Intel, the Intel logo, and Xeon Inside are trademarks of Intel Corporation in the U.S. and/or other countries. HP is the sponsor …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds