读书人

根据string查找treeview上一节点

发布时间: 2012-12-17 09:31:40 作者: rapoo

根据string查找treeview下一节点
TreeView
01 中国
01-01 北京
01-01-01 东城区
01-01-02 西城区
...
01-02 上海
01-02-01 黄浦区
...
...
...

当我搜索"区"时,能定位当前节点后面Node.Text含"区"的节点。也就是查找下一含string的节点,若当前节点为空则从头开始查询。

能给予源代码。谢谢
[最优解释]
http://bbs.csdn.net/topics/390300855
[其他解释]
google “C# treeview遍历”
[其他解释]
我懂得遍历,可是每次都是从头开始,我需要的是从下一节点开始,比如在记事本中查找,点查找会自动查找下一个,而不会每次都从头开始

引用:
google “C# treeview遍历”

[其他解释]
你不懂,如果你真的会使用递归的话,你就不会问了
[其他解释]
这种不行,我搜索“区”每次都是定位的东城区
我的要求,当现在定位在东城区节点上,再按查找,定位至西城区,然后再点,定位至黄浦区....

TreeNode CallFindNode(string tntext, TreeView treeView)
{
TreeNodeCollection nodes = treeView.Nodes;
foreach (TreeNode n in nodes)
{
TreeNode temp = FindTreeNode(tntext, n);
if (temp != null)
return temp;
}
return null;
}

TreeNode FindTreeNode(string tntext, TreeNode tnParent)
{
if (tnParent == null)
return null;
if (tnParent.Text.IndexOf(tntext, StringComparison.CurrentCultureIgnoreCase) > -1)
return tnParent;
TreeNode tnRet = null;
foreach (TreeNode tn in tnParent.Nodes)
{
tnRet = FindTreeNode(tntext, tn);
if (tnRet != null)


break;
}
return tnRet;
}


引用:
你不懂,如果你真的会使用递归的话,你就不会问了

[其他解释]
http://zhidao.baidu.com/question/254642617.html?quesup2

读书人网 >C#

热点推荐