Finding A Specific TreNode

J

Jeff Gaines

I have written a file manager in C#, it uses the NET Framework as far a
possible but dives into the API/COM for those functions not provided by NET.

It uses lazy loading for the nodes of the TreeView, i.e. it only adds
child directories when a node is expanded. The 'Name' property of each
node is set to the directory path so I can use the Node.Nodes.Find
function to find a specific node.

As a consequence when I want to select a specific TreeeNode (say from
clicking a 'favourite' folder) I have to start searching at the root node,
expand each node as I find it (so the children get added) and then
continue the search, like this:

Path to display: D:\Data\Visual Studio 2008\Projects

Split the path.
Start at the root node, collapse it then expand it.
Find the node for 'D:\'
Collapse/expand it
Using the 'D:\' node as a starting point find the 'D:\Data' node etc.

It's a recursive function and it works but according to the Ants profiler
it is a bottleneck.

Can anybody think of a quicker way of getting to a specified node, bearing
in mind it may not exist at the point the search starts?

I did try keeping nodes in a hash table keyed by path but that didn't seem
to be any quicker than the Node.Nodes.Find function.
 
A

Arne Vajhøj

I have written a file manager in C#, it uses the NET Framework as far a
possible but dives into the API/COM for those functions not provided by
NET.

It uses lazy loading for the nodes of the TreeView, i.e. it only adds
child directories when a node is expanded. The 'Name' property of each
node is set to the directory path so I can use the Node.Nodes.Find
function to find a specific node.

As a consequence when I want to select a specific TreeeNode (say from
clicking a 'favourite' folder) I have to start searching at the root
node, expand each node as I find it (so the children get added) and then
continue the search, like this:

Path to display: D:\Data\Visual Studio 2008\Projects

Split the path.
Start at the root node, collapse it then expand it.
Find the node for 'D:\'
Collapse/expand it
Using the 'D:\' node as a starting point find the 'D:\Data' node etc.

It's a recursive function and it works but according to the Ants
profiler it is a bottleneck.

Can anybody think of a quicker way of getting to a specified node,
bearing in mind it may not exist at the point the search starts?

I did try keeping nodes in a hash table keyed by path but that didn't
seem to be any quicker than the Node.Nodes.Find function.

I suspect that it is the file system access that cost.

And if you really want to have all parents node loaded, then I
doubt there is much you can do.

You could consider lazy loading some of the parents information.

Arne
 
A

Arne Vajhøj

I suspect that it is the file system access that cost.

And if you really want to have all parents node loaded, then I
doubt there is much you can do.

You could consider lazy loading some of the parents information.

And there are actually 2 flavors of lazy loading:
- traditional where you load when requested by user
- GUI where you show the user the favorite and then you load
all the parents info in the background so it is ready when
the user request

Arne
 
J

Jeff Gaines

And there are actually 2 flavors of lazy loading:
- traditional where you load when requested by user
- GUI where you show the user the favorite and then you load
all the parents info in the background so it is ready when
the user request

Thanks Arne :)

I need to learn about threading, looks like the time has come....
 
J

Jeff Johnson

Thanks Arne :)

I need to learn about threading, looks like the time has come....

Threading in and of itself is pretty simple. SYNCHRONIZING threads, that's
something else....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top