One of the problems is that I don't know in advance how big the dataset is
either :( I'm testing all my code against two datasets - one we consider
"average" and a much, much larger one. I do have a well-defined structure
for my TreeView though, so I know exactly how many levels deep it needs to
be and exactly how the data will be grouped together. The dynamic node
filling is a very good idea. I'll have to work out some of the kinks as far
as 'synchronizing' (if that's the right word) the TreeView population with
the SQL queries on their separate thread.
I'm also playing with the idea of creating a new subclass or two of TreeNode
that expose some more properties I can use to get my SQL queries and node
fills in sync with one another. One property I'm working on is a "Level"
property that tells you which level a particular TreeNode is on - for
instance, the root node of the TreeView would be Level 0, it's immediate
children would be Level 1, etc., etc. What I've come up with as far as a
function is pretty useful, but I definitely don't want to re-invent the
wheel - is there a function or property out there that does this already?
All this brings up one more question (I'm about to test this myself) - do
you have to cast a subclass of TreeNode back to (TreeNode) in order to work
with it in a TreeView?
Thanks for the help,
Michael C.
I'm not sure how big the dataset is but what really helps is not
completely filling the tree at once but per node, when they're expanded. This means
that you cache the data in a dataset or other bucket and add the child nodes to
the expanded node when the user expands a node.
Very easy to do and very efficient. Explorer for example does this too,
it would take ages to fill hte complete tree at the left.
Add a dummy node to every node which should have childs (and remove that
one when you expand the node) to be able to click it open.
FB
--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP