首页 > 代码库 > TreeView 查找指定节点

TreeView 查找指定节点

/// <summary>    /// 查找指定节点    /// </summary>    /// <param name="tnParent">节点</param>    /// <param name="strValue">值</param>    /// <returns></returns>    private TreeNode FindNode(TreeNode tnParent, string strValue)    {        TreeNode treeNode2 = new TreeNode();        string venueCode = "";        if (tnParent == null) return null;        if (tnParent.Value =http://www.mamicode.com/= strValue) return tnParent;"")            {                //记录节点                treeNode2 = tn;                venueCode = tn.Value;            }            else            {                //当选择节点发生变化时                if (venueCode != tn.Value)                {                    treeNode2.Collapse();                    venueCode = tn.Value;                    treeNode2 = tn;                }            }            tnRet = FindNode(tn, strValue);            if (tnRet != null) break;        }        return tnRet;    }方法调用如下://循环查找节点foreach (TreeNode node in this.TreeView1.Nodes){    TreeNode treeNode = FindNode(node, venueCode);    if (treeNode != null)    {        treeNode.CollapseAll();        treeNode.Selected = true;        state = 1;        break;     }}