/// <summary>
/// TReeView操作的类
/// </summary>
public class TreeViewOpt
{
/// <summary>
/// 根据节点名称遍历树节点
/// </summary>
/// <param name="NodeText">节点名称包含的关键字</param>
/// <param name="tnParent">节点集合</param>
/// <returns>查找到的第一个节点</returns>
public static TreeNode FindTreeNode(string NodeText, TreeNode tnParent)
{
if (tnParent == null)
return null;
if (tnParent.Text.IndexOf(NodeText)>=0)
return tnParent;
TreeNode tnRet = null;
foreach (TreeNode tn in tnParent.Nodes)
{
tnRet = FindTreeNode(NodeText, tn);
if (tnRet != null)
break;
}
return tnRet;
}
/// <summary>
/// 根据节点名称遍历树节点
/// </summary>
/// <param name="NodeText">节点名称包含的关键字</param>
/// <param name="treeView">TreeView对象</param>
/// <returns>查找到的第一个节点</returns>
public static TreeNode CallFindNode(string NodeText, TreeView treeView)
{
TreeNodeCollection nodes = treeView.Nodes;
foreach (TreeNode n in nodes)
{
TreeNode temp = FindTreeNode(NodeText, n);
if (temp != null)
return temp;
}
return null;
}
}