Key code:
#regionCheck if the node text exists// <summary> /// Check if the node text exists // </summary> /// <param name= "tree" >TreeView</param> /// <param name= "key" > node text </param> <returns> Presence </returns> Public Static BOOLChecknodeexist ( ThisTreeView Tree,stringKey) {BOOL_exists =false; for(inti = 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 BOOLChecknodeexist (TreeNode node,stringKey) { for(inti = 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; }#endregionCheck if the node text exists
Hope to be helpful!
[WinForm] The TreeView checks if the node text exists