Not sure if I understand the question correctly but from what I gather you want to remove matching nodes regardless on what level they are found. In order to do that you need a recursion.
Have a look at the following example. First I add some nodes to the tree view and then remove all elements containing text
B
Dim treenode As TreeNode
treenode = Me.TreeView1.Nodes.Add("A")
treenode.Nodes.Add("B")
treenode.Nodes.Add("C")
treenode = Me.TreeView1.Nodes.Add("B")
treenode = treenode.Nodes.Add("C")
treenode.Nodes.Add("D")
treenode = Me.TreeView1.Nodes.Add("C")
treenode = treenode.Nodes.Add("B")
treenode.Nodes.Add("A")
Me.RemoveNodesByText("B", Me.TreeView1)
End Sub
Private Function RemoveNodesByText(ByVal nodetext As String, ByVal treeview1 As TreeView, Optional childnode As TreeNode = Nothing) As Boolean
Dim nodesToIterate As TreeNodeCollection
If childnode Is Nothing Then
nodesToIterate = treeview1.Nodes
Else
nodesToIterate = childnode.Nodes
End If
For nodecounter As Integer = nodesToIterate.Count - 1 To 0 Step -1
RemoveNodesByText(nodetext, treeview1, nodesToIterate(nodecounter))
If nodesToIterate(nodecounter).Text = nodetext Then
nodesToIterate(nodecounter).Remove()
End If
Next
Return True
End Function
One thing is that in the example code the new node isn't added inside the recursive function. Otherwise multiple new nodes would be created so if you want to ensure that only one node of a kind exists, first remove duplicates and after that add the new node to desired location.