Hi,
How can I find and delete same text nodes in the TreeView?
Like this (must be delete which it is signed with red rectangle);
http://myimgs.net/images/qtrj.jpg
Printable View
Hi,
How can I find and delete same text nodes in the TreeView?
Like this (must be delete which it is signed with red rectangle);
http://myimgs.net/images/qtrj.jpg
You're just going to have to traverse the entire tree. Add the text of each node to a list as you go. When you reach each node check whether its text is already in the list. If it is then delete the node, otherwise add the text to the list and continue. Traversing a tree is best done using recursion. Here's a skeleton to get you started:You'd start that going by passing it the Nodes collection of the root of your search, which would normally be the TreeView itself.Code:Public Sub VisitAllNodes(ByVal nodes As TreeNodeCollection)
For Each node As TreeNode In nodes
MessageBox.Show(node.Text)
'Call the method recursively.
Me.VisitAllNodes(node.Nodes)
Next node
End Sub
Hi jmcilhinney,
fine to see you again.
When I calling your code like this;
All of nodes are coming in msgbox and how can I collect all nodes and find the same texts and then delete it.Code:Call VisitAllNodes(TreeView1.Nodes)
Best Regards.
The best way to handle this situation is Not to add duplicate nodes to your treeview in the first place.... When you add child nodes to a parent node, just check the parent node to see if it already contains that specific new node. If it does, don't add the new node to it.
yeah this way to be perfectly resolved the problem.
Thank you very very much guys.