using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SuijiNumber
{
class Program
{
static void Main(string[] args)
{
string searchKey = "财政局";
TreeNode parentNode = null; // 注意要设置该值,使其不能为空,一般为一棵树的根结点。
TreeNode node = BianLi(parentNode, searchKey);
if (node != null)
{
// 则找到
}
}
static TreeNode BianLi(TreeNode parentNode,string searchKey)
{
foreach (TreeNode node in parentNode.Nodes)
{
if (node.Text == searchKey)
{
return node;
}
else if (node.Nodes.Count >1)
{
for (int i = 0; i < node.Nodes.Count; i++)
{
BianLi(node.Nodes[i], searchKey);
}
}
}
return null;
}
}
}
foreach(treenode node in treeview.nodes)
{
if(node.text=="你想要的值")
{}
}
要详细点