Q: How to expand/collapse a branch?
A: If you want to expand or collapse one only item use
Code:
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:
Code:
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);
}
}
}