Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. too many items in treeview

too many items in treeview

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmsdata-structuresperformancehelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Peter Molnar
    wrote on last edited by
    #1

    Hi, I am populating a treeview with some data and since there are too many and too long items my app requires even more and more memory. To avoid this I decided to use single select mode and add only those items to the tree which belong to the CURRENTLY expanded node. If this node gets collapsed all items are removed from this node. In that way the app's footprint might be significantly reduced. Problem: the whole tree must be kept in and read in from a file according to a certain algorithm. I need your advice as to how you would do this. Thanks in advance. Bunburry

    P 1 Reply Last reply
    0
    • P Peter Molnar

      Hi, I am populating a treeview with some data and since there are too many and too long items my app requires even more and more memory. To avoid this I decided to use single select mode and add only those items to the tree which belong to the CURRENTLY expanded node. If this node gets collapsed all items are removed from this node. In that way the app's footprint might be significantly reduced. Problem: the whole tree must be kept in and read in from a file according to a certain algorithm. I need your advice as to how you would do this. Thanks in advance. Bunburry

      P Offline
      P Offline
      pnpfriend
      wrote on last edited by
      #2

      // 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 ); do{ CollapseBranch( hti ); }while( (hti = GetNextSiblingItem( hti )) != NULL ); } } Expanding a branch -------------------------------------------------------------------------------- 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() ); } search more in codeguru and codeproject

      P 1 Reply Last reply
      0
      • P pnpfriend

        // 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 ); do{ CollapseBranch( hti ); }while( (hti = GetNextSiblingItem( hti )) != NULL ); } } Expanding a branch -------------------------------------------------------------------------------- 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() ); } search more in codeguru and codeproject

        P Offline
        P Offline
        Peter Molnar
        wrote on last edited by
        #3

        I must have asked in the wrong way: The real question is how can I serialize a treeview into a file so that I can retrieve its nodes any time. When I expand an item, I have to read in its childs from the file, when I collapse delete all items in this node because all subitems are saved in the file in question. Anyway thanks for the feedback. Bunburry

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups