MFC Tree Control: How to expand/collapse a branch?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: MFC Tree Control: How to expand/collapse a branch?

  1. #1
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443

    MFC Tree Control: How to expand/collapse a branch?

    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);
        }
      }
    }
    Last edited by Andreas Masur; July 25th, 2005 at 03:57 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center