Expanding a branch

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.




The treeview has built in support for expanding expanding the outline one
level at a time. If you want to completely expand a branch, the code below
will help. It uses recursion to expand all items. The last line, that is,
the call to EnsureVisible() is useful when this code is hooked up to a
user interface. After expanding the outline branch, the previously selected
item may have scrolled off and calling EnsureVisible() brings it back.

 
// ExpandBranch – Expands a branch completely
// hti          – Handle of the tree item to expand
void CTreeCtrlX::ExpandBranch( HTREEITEM hti )
{
        if( ItemHasChildren( hti ) ){
                Expand( hti, TVE_EXPAND );
                hti = GetChildItem( hti );
                do{
                        ExpandBranch( hti );
                }while( (hti = GetNextSiblingItem( hti )) != NULL );
        }
        EnsureVisible( GetSelectedItem() );
}

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read