[转载]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; }