G
Guest
Please help!!! I have a TreeView something like this:
Numbers
---Range 1
-------1
-------2
-------3
---Range 2
-------1
-------2
-------3
How can I select the node that reads "1" at range 2 from my VB .NET code?
i find this sample and use it but there is a big problem
it find the 1 but it is not at range 2
it fınd it from range 1
can you help me
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'look for a node with a text property value of 'Node3'
TreeView1.SelectedNode = GetNode("Node3", TreeView1.Nodes)
'ensure the focus set on the node
TreeView1.Select()
End Sub
Private Function GetNode(ByVal text As String, ByVal parentCollection As TreeNodeCollection) As TreeNode
Dim ret As TreeNode
Dim child As TreeNode
For Each child In parentCollection 'step through the parentcollection
If child.Text = text Then
ret = child
ElseIf child.GetNodeCount(False) > 0 Then ' if there is child items then call this function recursively
ret = GetNode(text, child.Nodes)
End If
If Not ret Is Nothing Then Exit For 'if something was found, exit out of the for loop
Next
Return ret
end function
Numbers
---Range 1
-------1
-------2
-------3
---Range 2
-------1
-------2
-------3
How can I select the node that reads "1" at range 2 from my VB .NET code?
i find this sample and use it but there is a big problem
it find the 1 but it is not at range 2
it fınd it from range 1
can you help me
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'look for a node with a text property value of 'Node3'
TreeView1.SelectedNode = GetNode("Node3", TreeView1.Nodes)
'ensure the focus set on the node
TreeView1.Select()
End Sub
Private Function GetNode(ByVal text As String, ByVal parentCollection As TreeNodeCollection) As TreeNode
Dim ret As TreeNode
Dim child As TreeNode
For Each child In parentCollection 'step through the parentcollection
If child.Text = text Then
ret = child
ElseIf child.GetNodeCount(False) > 0 Then ' if there is child items then call this function recursively
ret = GetNode(text, child.Nodes)
End If
If Not ret Is Nothing Then Exit For 'if something was found, exit out of the for loop
Next
Return ret
end function