Adding nodes to a treeview only when needed

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
* "=?Utf-8?B?cG1jZ3VpcmU=?= said:
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.
 
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 said:
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.
 
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? :-)
 
Yes but how many are there? (approximately). I assume you also only need to
load the tree once.

pmcguire said:
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?
:-)
 
Back
Top