We help IT Professionals succeed at work.

Treeviews: pruned, trimmed, truncated?

adopo asked
I have a large dataset that changes rapidly and I want to allow the user to move through it using multiple treeviews.  I want to dynamically create treeviews that represent the small amount of data structure that the user is navigating.  The treeview will receive notifications as the underlying data is changed and
I want to trim any portion of the treeview that has been changed in the data but is not being viewed. If is it being viewed, I would like to update it when it changes. I think I should be able to assume that if a portion of the treeview is already built then it is valid because if it were no longer valid, it would be trimmed/changed.  I need to distinguish between a node that has no children and a node that is trimmed or unbuilt.  


1. Is this a feasible and practical approach?

2. Do you have a better idea?

3. Any examples similar to this? I'm interested in code examples or even just knowing about an application that uses treeviews in this way.  

I will split points and/or post additional points for the most helpful info. Please do consider the nature of my question and don't give me general treeview examples.  I already know how to use a treeview. Any info related to a good interface design for this functionality would be  especially helpful.  
Watch Question


I'm actually doing something very similar in my current application. Beleive me it's revoltingly tricky, but produces fantastic results - the clients love it when they see the data changing on their screen in real time.

Is this a feasible and practical approach?
Yes and no - it's very compliated to do in a multiuser environment - you need to create a distributed event mechansim to signal updates, I used short text messages sent out over sockets with a central server fielding the messages around.

I actually use my own tree control which does neat things like columns, multi-select, ole d&d using a full-on OO paradigm - you don't add nodes, you add objects which implement the ITree interface. But that's a different story, so I won't go into it ;)

When I load a node, I check to see if the data at node has children (guessing in some cases to save database time, e.g. data with an 'iscategory' flag usually has children. If the data has children, I load a dummy node into the tree to mark it as loading and get the plus sign.
When a node is expanded, I check to see if there is only one child, and if there is, if it's a dummy, I go off and load the data.

I use four messages in general -
Update - a record has been updated, find the node in the tree and refresh it
Delete - a record has been deleted, find the node in the tree and remove it
Add - a record has been added to another node, find the node, store its expansion state and remove its children. Add the loading and restore its expansion (so it then goes off and gets the data)
Remove - a record has been removed from another node - find the sub node and remove it.

The results are way cool - it also means that you don't have to write code to tie your editor screens into your display screens - everything uses the distributed events, so the screens are updated, even if there are several affected.
One note - My data is not particularly volatile so the network can easily cope with the messages (only a few thousand updates a day).
The trees are nice and responsive with on average 10000 items 'virtually' in them - just make sure the child retreival code is quick.


I'm so glad you responded!  I've got a simple distributed event mechanism working, also using sockets and short messages.  I really liked your commments. I'm having a lot of touble coming up with a clean design for a treeview class.  Do you update objects that are not currently visible?  For example, once a "node" is viewed (I understand you aren't actually using nodes but I don't know what else to call it) do you always update it when the underlying data changes even if it is not visible?  Do you ever trim or drop nodes because they are no longer viewed even if the underlying data is still there? If not,  does that mean that the longer the treeview is used, the slower it gets?   Have you seen any applications besides your own that do this with treeviews?

Hi - sorry for not responding, but EE's had problems as you probably know.
I always update nodes if they're loaded; but I don't ever unload nodes- It might be a good idea to do this on a standard tv as they get a bit slow when there's lots of nodes. My tree control seems to cope with large amounts of nodes quite well, but it's a reasonable idea to prune to save memory - especially if you're using lots of different images, win9x resources soon get eaten.




I figured thats why you hadn't responded.  This site has been a mess.  I'd stop coming here if it weren't so darn useful.  

I found your answer to be very helpful because it helped to clarify my thinking. It is more clear to me now that the problem is that my underlying data is changing very rapidly (it's being updated by another process, not by a person).  So my concern should be not with the size of the treeview as much as the time and effort making lots of updates to nodes that aren't currently useful (because they aren't currently viewed and might never be viewed again).  

I'm thinking I should take a page from your book and write a custom treeview specifically designed for this, which is really a different semantic than the delivered treeview.  That way the But on the other hand, I have work to do so I'm a little conflicted.  

In the tv that you wrote, are you wrapping an existing treeview control for the display or are you actually generating the whole thing from scratch?

Explore More ContentExplore courses, solutions, and other research materials related to this topic.