Click to See Complete Forum and Search --> : MFC Tree Control: How to expand/collapse a branch?


Gabriel Fleseriu
February 14th, 2003, 09:09 AM
Q: How to expand/collapse a branch?

A: If you want to expand or collapse one only item use


m_tree.Expand(hItem, TVE_EXPAND); // or 'TVE_COLLAPSE'

If you want to expand or collapse an item and all of its children use something like this:


void ExpandTreeItem(const CTreeCtrl &tree, HTREEITEM hItem, UINT nCode)
{
HTREEITEM hChild;

if(tree.ItemHasChildren(hItem))
{
tree.Expand(hItem, nCode);
hChild = tree.GetChildItem(hItem);

while(hChild)
{
ExpandTreeItem(tree, hChild, nCode);
hChild = tree.GetNextItem(hChild, TVGN_NEXT);
}
}
}

<br>