468,161 Members | 2,152 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,161 developers. It's quick & easy.

Adding nodes to a treeview only when needed

I have a treeview with a lot of nodes. I want to load only the nodes that are initially visible when the form loads, and then continue to populate it in background and/or when the nodes are required by the user either scrolling or performing some other action that would move the treeview window to a particular "unloaded" node in the treeview

Any advice on how to go about this? It seems I need a way of sensing a scroll event in the treeview control, but it does not appear that the treeview control exposes this event

Thanks for the help.
Nov 20 '05 #1
4 1964
* "=?Utf-8?B?cG1jZ3VpcmU=?=" <an*******@discussions.microsoft.com> scripsit:
I have a treeview with a lot of nodes. I want to load only the nodes
that are initially visible when the form loads, and then continue to
populate it in background and/or when the nodes are required by the user
either scrolling or performing some other action that would move the
treeview window to a particular "unloaded" node in the treeview.


Instead of doing that, you can add only the top-level nodes and dummy
subnodes (one level) where required. When the control is displayed to
the user, all branches of the tree are collapsed. If the user expands a
node, you remove the subitem (or change it) and add the appropriate
items.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
What you are looking for is a "virtual tree view". As far as I am aware,
the vanilla tree view in Forms wasn't written to perform this (or anything
much come to think of it!).

The approach really depends on how many items are in the root of your tree
view. If you have literally thousands, populating the tree still shouldn't
take all that long (I've tested mine with a full tree of over 6,000 items
and ok, it takes a couple of seconds, but it isn't too annoying). The
issue is what you are doing in order to fetch a given item. For example, I
fetch my entire database tree into memory (in my own tree structure, not a
tree view), then I just go through the whole thing, adding nodes to the tree
view. Its quicker than fetching one item from the database, adding it to
the tree, going back and fetching the next etc.

Also, consider categorisation. Are you sure you need a tree this large?

Why not just populate the root with the 1st and 2nd level nodes and then
when the user clicks to open a node, populate that node with the 3rd level
and so on.

Just some ideas ;)

"pmcguire" <an*******@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
I have a treeview with a lot of nodes. I want to load only the nodes that are initially visible when the form loads, and then continue to populate it
in background and/or when the nodes are required by the user either
scrolling or performing some other action that would move the treeview
window to a particular "unloaded" node in the treeview.
Any advice on how to go about this? It seems I need a way of sensing a scroll event in the treeview control, but it does not appear that the
treeview control exposes this event.
Thanks for the help.

Nov 20 '05 #3
Yes, I am already employing that technique. The problem is that there are a lot of top-tier nodes. I anticipate that the next suggestion is to somehow reduce the number of top-tier nodes. I have already reduced them as much as possible (given client requirements)

So, assuming that I want to do what I said I want to do, how do I do it? :-)
Nov 20 '05 #4
Yes but how many are there? (approximately). I assume you also only need to
load the tree once.

"pmcguire" <an*******@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...
Yes, I am already employing that technique. The problem is that there are a lot of top-tier nodes. I anticipate that the next suggestion is to
somehow reduce the number of top-tier nodes. I have already reduced them as
much as possible (given client requirements).
So, assuming that I want to do what I said I want to do, how do I do it?

:-)
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by sho_nuff | last post: by
4 posts views Thread by Chuck Bowling | last post: by
4 posts views Thread by JoKur | last post: by
1 post views Thread by garyusenet | last post: by
6 posts views Thread by =?Utf-8?B?QnJhZA==?= | last post: by
1 post views Thread by Bart Steur | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.