[转载]TreeView的节点遍历 - 部落酋长 - 博客园

baacloud免费翻墙vpn注册使用

[转载]TreeView的节点遍历 – 部落酋长 – 博客园.

 

foreach (TreeNode td in treeView1.Nodes)
                {
                    TreeNode targetNode = SearchNode(td, selectParentNum);
                    if (targetNode != null)
                    {
                        treeView1_AfterSelect(treeView1, new TreeViewEventArgs(targetNode));
                        break;
                    }
                }

/// <summary>
/// 遍历TreeView节点
/// </summary>
/// <param name="td">ParentNode</param>
/// <param name="selectParentNum">条件</param>
/// <returns></returns>

private TreeNode SearchNode(TreeNode td, string selectParentNum)
        {
            if (td.ToolTipText == selectParentNum)
            {
                return td;
            }
            TreeNode targetNode = null;
            foreach (TreeNode childNodes in td.Nodes)
            {
                targetNode = SearchNode(childNodes, selectParentNum);
                if (targetNode != null)
                    break;
            }
            return targetNode;
        }
赞(0) 打赏
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏