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 );
                        CollapseBranch( hti );
                }while( (hti = GetNextSiblingItem( hti )) != NULL );


More by Author

Must Read