Finding A Specific TreNode

  • Thread starter Thread starter Jeff Gaines
  • Start date Start date
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.
 
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
 
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
 
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....
 
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....
 
Back
Top