Article ID: 149323
Article Last Modified on 6/24/2004
TreeView1.Nodes.Add , , , "MyText"If the Root property is used with any descendant nodes of this first node, it will work correctly. However, if another root level node is added with the above line of code, then the Root property of all descendant nodes will still return a reference to the first node added.
Function FindRoot(ByVal nodX As Node) As Node
Dim n As Integer
On Error GoTo ErrHandler
n = nodX.Index
While n <> nodX.Root.Index
n = TreeView1.Nodes(n).Parent.Index
Wend
ErrHandler:
Set FindRoot = TreeView1.Nodes(n)
End Function
Sub Form_Click()
With TreeView1
.Nodes.Add , , , "abc"
.Nodes.Add , , , "def"
MsgBox .Nodes(1).Root.Text 'returns 'abc'
MsgBox .Nodes(2).Root.Text 'returns 'abc' also - you expect it
' to return 'def'
End With
End Sub
Additional query words: kbControl kbVBp500bug kbVBp400bug kbVBp kbdsd kbDSupport
Keywords: kbbug KB149323