Treeview Search and View Node

AukI

Member
Joined
Nov 20, 2010
Messages
17
Programming Experience
3-5
This below code does work fine don't select a node but it goes through it... I debugged it .. Can I anyone help ..?



Thanks In advance.



VB.NET:
    Public Function TreeView_Search_InsideNode(ByVal ParentNode As TreeNode, ByVal SearchVal As String, Optional ByVal Selection As Boolean = False) As TreeNode
        Dim tmpNode As TreeNode

        If ParentNode.Text = SearchVal Then
            If Selection = True Then
                'ParentNode.Parent.TreeView.SelectedNode = ParentNode
                ParentNode.TreeView.SelectedNode = ParentNode

            End If
            Return ParentNode
        Else
            Dim child As TreeNode
            If ParentNode IsNot Nothing AndAlso ParentNode.Nodes IsNot Nothing AndAlso ParentNode.Nodes.Count > 0 Then
                For Each child In ParentNode.Nodes
                    tmpNode = TreeView_Search_InsideNode(child, SearchVal, Selection)
                    If Not tmpNode Is Nothing Then
                        If Selection = True Then tmpNode.TreeView.SelectedNode = tmpNode
                        Return tmpNode
                    End If
                Next
            End If
        End If

        Return Nothing
    End Function
 
Top Bottom