Public Function SearchNodes(TV As TreeView, Str As String, Optional PartialText As Boolean True, Optional IgnoreCase As Boolean True) As Collection Dim mCol As New Collection Dim Node As Node For Each Node In TV.Nodes If PartialText Then If IgnoreCase Then If UCase$(Node.Text) Like "*" & UCase$(Str) & "*" Then mCol.Add Node Else If Node.Text Like "*" & Str & "*" Then mCol.Add Node End If Else If IgnoreCase Then If UCase$(Node.Text) = UCase$(Str) Then mCol.Add Node Else If Node.Text = Str Then mCol.Add Node End If End If Next Node Set SearchNodes = mCol End Function
Dim Node As Node For Each Node In SearchNodes(TV, InputBox("Entrez un morceau de la chaîne a rechercher.")) MsgBox Node.Text Next Node
Option Explicit Private Sub Form_Load() TV.Nodes.Add Key:="Verbes", Text:="Verbes" TV.Nodes.Add "Verbes", tvwChild, Text:="Construire" TV.Nodes.Add "Verbes", tvwChild, Text:="Courir" TV.Nodes.Add "Verbes", tvwChild, Text:="Bondir" Dim Node As Node MsgBox "Recherche des verbes contenant ""on""" For Each Node In SearchNodes(TV, "on") MsgBox Node.Text Next Node End Sub Public Function SearchNodes(TV As TreeView, Str As String, Optional PartialText As Boolean True, Optional IgnoreCase As Boolean True) As Collection Dim mCol As New Collection Dim Node As Node For Each Node In TV.Nodes If PartialText Then If IgnoreCase Then If UCase$(Node.Text) Like "*" & UCase$(Str) & "*" Then mCol.Add Node Else If Node.Text Like "*" & Str & "*" Then mCol.Add Node End If Else If IgnoreCase Then If UCase$(Node.Text) = UCase$(Str) Then mCol.Add Node Else If Node.Text = Str Then mCol.Add Node End If End If Next Node Set SearchNodes = mCol End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question