Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
For Each node As TreeNode In TreeView1.Nodes
If (node.Text = txtSearch.Text) Then
node.Text = "" & node.Text & ""
ExpandAllNodes(node)
node.Select()
ElseIf (node.ChildNodes) IsNot Nothing Then
CheckChildNodes(node)
End If
Next
TreeView1.ExpandAll()
End Sub
Private Sub CheckChildNodes(ByVal node As TreeNode)
For Each childNode As TreeNode In node.ChildNodes
If childNode.Text = txtSearch.Text Then
childNode.Text = "" & childNode.Text & ""
ExpandAllNodes(childNode)
childNode.Select()
ElseIf childNode.ChildNodes IsNot Nothing Then
CheckChildNodes(childNode)
End If
Next
End Sub
Private Sub ExpandAllNodes(ByVal node As TreeNode)
Dim nodeParent As TreeNode = node.Parent
While (nodeParent.Parent IsNot Nothing)
nodeParent = nodeParent.Parent
End While
nodeParent.ExpandAll()
End Sub
Private Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged
Label1.Text = "Hi " + TreeView1.SelectedNode.Text
End Sub
|