NextVisibleNode is not consistent

R

Ryan Liu

Hi,

I am using TreeNode.NextVisibleNode to loop though all nodes in a tree. I
think this is faster than using recursive algorithm.

But I found this method is not consistent. Sometime it returns right
treeNode, sometime it returns null.

What does "Visible" mean? It is not necessary shown on the form and visible
to our eyes, right?

And form my TreeView, there are multiple first lever nodes(multiple root),
is this a problem? But why it is not consistent?

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.

Thanks!
Ryan
 
P

Peter Duniho

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
 
R

Ryan Liu

Peter,

Thanks a lot for your detailed reply!

I think I mis-understanding "Visible".

-Ryan
 

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