标签:
关键代码:
#region 检查节点文本是否存在 /// <summary> /// 检查节点文本是否存在 /// </summary> /// <param name="tree">TreeView</param> /// <param name="key">节点文本</param> /// <returns>是否存在</returns> public static bool CheckNodeExist(this TreeView tree, string key) { bool _exists = false; for (int i = 0; i < tree.Nodes.Count; i++) { TreeNode _curNode = tree.Nodes[i]; if (string.Compare(_curNode.Text, key, true) == 0) _exists = true; else _exists = CheckNodeExist(tree.Nodes[i], key); } return _exists; } private static bool CheckNodeExist(TreeNode node, string key) { for (int i = 0; i < node.Nodes.Count; i++) { TreeNode _node = node.Nodes[i]; if (string.Compare(_node.Text.Trim(), key, true) == 0) { return true; } if (_node.Nodes.Count > 0) { CheckNodeExist(_node, key); } } return false; } #endregion 检查节点文本是否存在
希望有所帮助!
标签:
原文地址:http://www.cnblogs.com/Yan-Zhiwei/p/4423962.html