在访问TreeView控件的所有节点 [英] Accessing all the nodes in TreeView Control

查看:76
本文介绍了在访问TreeView控件的所有节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组节点和子节点的 TreeView控件控制。例如:




ROOT有A,B,C



$。 b $ b

一个具有A1,A2,A3,然后将该A1,A2中还包含像X1,X2,X3和等一些节点。很多这样子节点的存在。我知道这是可能使用循环使用循环。



我只是想访问 TreeView控件使用一个或两个for循环的控制。



有任何算法为或有任何其他方式?



还有一个问题:它可能有一个对象,或使用任何库函数字符串树节点的路径?例如:

 串S = TreeView1.Nodes [I] .Nodes [J] .Nodes 


解决方案

不要使用嵌套的循环,但去像一个递归解决方案:

 无效ListNodes(TreeNode的节点)
{
的foreach(在node.Nodes VAR子节点)
{
ListNodes(子节点);
}
//打印出点
}

调用此。功能为您的根节点



有关的另一个问题:检查完整路径属性


I have a TreeView Control with set of nodes and child nodes. For example:

ROOT has A,B,C.

A has a1, a2, a3 and then that a1, a2 also contains some nodes like x1, x2, x3 and so on. Like this many subnodes are there. I know it is possible to use loops with a for loop.

I just want to access all the nodes in TreeView control using one or two for loops.

Is there any algorithm for that or is there any other way?

One more question: Is it is possible to have the path of a tree node in an object or in a string using any library functions? For example:

string S = TreeView1.Nodes[i].Nodes[j].Nodes

解决方案

Don't use nested loops, but go for an recursive solution like:

void ListNodes( TreeNode node )
{
  foreach( var subnode in node.Nodes )
  {
    ListNodes( subnode );
  }
  // Print out node
}

Call this function for your root node.

For your additional question: check the FullPath property.

这篇关于在访问TreeView控件的所有节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆