On Fri, 01 Jun 2007 19:15:07 -0700, Ryan Liu <Ry*******@gmail.comwrote:
I am using TreeNode.NextVisibleNode to loop though all nodes in a tree. I
think this is faster than using recursive algorithm.
I suppose that depends on what you are actually trying to do. But if you
are literally trying to visit each node in the tree, it's faster but only
because it doesn't produce the desired results.
But I found this method is not consistent. Sometime it returns right
treeNode, sometime it returns null.
If there is no visible node after the one you're looking at, it will
return null. Are you saying that it returns null when there *is* a
visible node after the one you're accessing the property from?
What does "Visible" mean? It is not necessary shown on the form and
visible
to our eyes, right?
"Visible" means that the node is displayed on the TreeView. It
corresponds to the TreeNode.IsVisible property, which is true as long as
the tree node is at least partially in view.
And form my TreeView, there are multiple first lever nodes(multiple
root),
is this a problem? But why it is not consistent?
There should be no trouble with multiple root-level nodes.
And even TreeView has multiple root nodes, all those first level nodes
are
belong to one parent TreeNode. I just don't want this real root TreeNode
shown on the treeview.
Then don't create it. The TreeView instance has a TreeNodeCollection that
contains all the root level nodes. If you want all of your root level
nodes to be at the actual root level, then don't make them children of
some single root level node. Just add them to the TreeView itself.
Pete