TreeView的节点遍历
调用遍历方法
foreach (TreeNode td in treeView1.Nodes)
{
TreeNode targetNode = SearchNode(td, selectParentNum);
if (targetNode != null)
{
treeView1_AfterSelect(treeView1, new TreeViewEventArgs(targetNode));
break;
}
}
foreach (TreeNode td in treeView1.Nodes)
{
TreeNode targetNode = SearchNode(td, selectParentNum);
if (targetNode != null)
{
treeView1_AfterSelect(treeView1, new TreeViewEventArgs(targetNode));
break;
}
}
遍历TreeView节点
/**//// <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;
}
/**//// <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;
}