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. Asynchronously inserting large number of items into TreeView

Asynchronously inserting large number of items into TreeView

Scheduled Pinned Locked Moved C / C++ / MFC
wpfdata-structuresxmlhelpquestion
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.
  • H Offline
    H Offline
    henchook
    wrote on last edited by
    #1

    I need to insert a very large number of items into a CTreeView derived control. This insertion takes a long time, so I am doing is asynchronously. My problem is: whenever I call InsertItem, the tree selection jumps to the newly inserted item. I want to prevent this, so that my user sees the tree being built, but is able to select an item in the tree and have the selection remain on that item. How would I go about doing this? I tried looking for and using different window styles, and I tried intercepting the TVN_SELCHANGED and TVN_SELCHANGING messages, but wasn't quite able to achieve anything... I want it to behave sort of like IE does when you open a huge (and I mean HUGE, as in 1MB) XML file.... IE parses the file in the background, and keeps adding new nodes to it, but you are able to view whichever part of the document (that has already been loaded you want). Thanks, -CD

    V 1 Reply Last reply
    0
    • H henchook

      I need to insert a very large number of items into a CTreeView derived control. This insertion takes a long time, so I am doing is asynchronously. My problem is: whenever I call InsertItem, the tree selection jumps to the newly inserted item. I want to prevent this, so that my user sees the tree being built, but is able to select an item in the tree and have the selection remain on that item. How would I go about doing this? I tried looking for and using different window styles, and I tried intercepting the TVN_SELCHANGED and TVN_SELCHANGING messages, but wasn't quite able to achieve anything... I want it to behave sort of like IE does when you open a huge (and I mean HUGE, as in 1MB) XML file.... IE parses the file in the background, and keeps adding new nodes to it, but you are able to view whichever part of the document (that has already been loaded you want). Thanks, -CD

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      One solution is to keep a reference of the current selected item. Upon inserting new items, call TreeView_Select(). Kuphryn

      H 1 Reply Last reply
      0
      • V valikac

        One solution is to keep a reference of the current selected item. Upon inserting new items, call TreeView_Select(). Kuphryn

        H Offline
        H Offline
        henchook
        wrote on last edited by
        #3

        The problem was that after inserting each item, there was a call to Expand(), which caused the treeview to scroll to the newly expanded icon. This did not have any visible effect when the tree was being populated off-screen, but once I started doing this in a separate thread after showing the treeview, it was apparent in the tree jumping all over the place. It turns out (this is code I inherited from someone else at my company) that the proper thing to do, instead of calling Expand() after inserting each item, is to set the State bits (and the mask bits) in the TVINSERTSTRUCT before inserting the item, this causes it to be expanded when it is inserted, without the tree scrolling to it. Thanks anyway for your help.

        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