How to search Node in Treeview Control

  1.  Private Function search(ByVal Nod As TreeNode, ByVal StrFind As String) As TreeNode
  2.         If Nod Is Nothing Then Nod = Me.Nodes(0)
  3.         Dim tmpNod As TreeNode
  4.  
  5.         If String.Compare(Nod.Text, StrFind, True) = 0 Then
  6.             Return Nod
  7.         Else
  8.             For Each mNod As TreeNode In Nod.Nodes
  9.                 tmpNod = search(mNod, StrFind)
  10.                 If Not tmpNod Is Nothing Then
  11.                     Return tmpNod
  12.                 End If
  13.             Next
  14.         End If
  15.         Return Nothing
  16.     End Function

Usage:

  1. dim nod as TreeNode
  2.  
  3. nod = search(me.MyTreeViewControl.Nodes(0), "My search")

, ,

  1. No comments yet.
(will not be published)
Submit Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Subscribe to comments feed
  1. No trackbacks yet.

SetPageWidth