Asynchronously inserting large number of items into TreeView
-
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
-
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
-
One solution is to keep a reference of the current selected item. Upon inserting new items, call TreeView_Select(). Kuphryn
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.