Does anyone have a custom function to Remove a child node from a TreeView and move it to another child?

That may not make sense, so here's an Example:

Private Sub Form_Load()
     Dim Test As Node
     Dim Test2 As Node

     Set Test = TreeView1.Nodes.Add(, , "Testing", "Testing")
     Test.Expanded = True
     Test.Bold = True

     Set Test2 = TreeView1.Nodes.Add(, , "Testing2, "Testing2")
     Test2.Expanded = True
     Test2.Bold = True

     TreeView1.Nodes.Add "Testing", tvwChild, "hello"

'function to Remove child node from parent and add it to another part.. ?? :lol:
Private Sub RemoveChildNode(tvTree As TreeView, strName As String)
     Dim i As Integer
     For i = tvTree.Nodes.Count To 0 Step - 1
          If strName = tvTree.Nodes("Testing").Text Then 'or something...
               ' remove strName from "Testing" part
               ' and add strName to "Testing2" part
          End If
     Next i
End Sub


'usage:
RemoveChildNode(TreeView1,"hello")

Get my drift? :D

Thanks in advance.

Hi,

Try this :

Private Sub RemoveChildNode(tvTree As TreeView, strName As String)
Dim i As Integer
Dim NFound As Boolean
NFound = False
For i = tvTree.Nodes.Count To 0 Step - 1
  If Trim(strName) = Trim(tvTree.Nodes(i).Text)  Then          
    TvTree.Nodes.Remove TvTree.Nodes(i)
    NFound = True
    Exit For
  End If
Next i
If NFound Then
   TVTree.Nodes.Add "Testing2", tvwChild, strName, strName
End If
End Sub

Regards
Veena

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.