/**
* 遍历树种的值步骤
* <summary>
* 1.查找TreeView控件是否有指定值的节点
* </summary>
* <param name="tvControl">TreeView控件</param>
* <param name="strValue">指定节点值</param>
* <returns></returns>
**/
public static TreeNode FindNode(TreeView tvControl, string strValue)
{
TreeNode tnRet=null;
foreach (TreeNode tn in tvControl.Nodes)
{
tnRet = FindNode(tn, strValue);
if (tnRet != null) break;
}
return tnRet;
}
/**
* 遍历树种的值步骤
* <summary>
* 2.查找当前节点下是否有指定值的节点
* </summary>
* <param name="tnParent">当前节点</param>
* <param name="strValue">指定节点值</param>
* <returns>TreeNode</returns>
**/
public static TreeNode FindNode(TreeNode tnParent, string strValue)
{
if(tnParent==null) return null;
if(tnParent.Value==strValue) return tnParent;
TreeNode tnRet = null;
TreeNode tnTemp = null;
foreach(TreeNode tn in tnParent.ChildNodes)
{
tnTemp = FindNode(tn, strValue);
if(tnTemp !=null && tnTemp.Value==strValue)
{
tnRet = tnTemp;
break;
}
}
return tnRet;
}
转载于:https://blog.51cto.com/andysu/951205