hi everyone...
i found this code on this forum.. but im not satisfied on the results.. i tried to recode it but no luck.. i just need your opinions... if you can give example... many thanks...
Function searchTreeview(ByVal SearchString As String, ByVal Nodes As TreeNodeCollection, _
Optional ByVal ExactMatch As Boolean = False, _
Optional ByVal Recursive As Boolean = True) _
As TreeNode
Dim ret As TreeNode
For Each tn As TreeNode In Nodes
If ExactMatch = True Then
If tn.Text = SearchString Then Return tn
Else
If tn.Text.IndexOf(SearchString) <> -1 Then Return tn
End If
If Recursive = True Then
If tn.Nodes.Count > 0 Then
ret = searchTreeview(SearchString, tn.Nodes, ExactMatch, Recursive)
If Not ret Is Nothing Then Return ret
End If
End If
Next
Return Nothing
End Function
Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonSearch.Click
Dim tn As TreeNode = searchTreeview(TextBoxWordFind.Text, TreeViewBible.Nodes, False, True)
If Not tn Is Nothing Then
TreeViewBible.SelectedNode = tn
TreeViewBible.SelectedNode.BackColor = Color.RoyalBlue
TreeViewBible.SelectedNode.ForeColor = Color.White
Else
MsgBox("no match")
End If
End Sub
as i went through this code... im not getting the result i wanted... im confused what indexof really do...
on my treeview (for example only)
Old book
- Book 1 : Title One
- Book 2 : Title Two
- Chapter 1
- Chapter 2
- Paragraph 1
- Chapter 3
here is my scenario...
the color red text are from database... and the black one are only hard coded...
when i search for "Book 1".. no match
but when i search for "1" only... it founds it...
i need to search for the whole "Book 1"...
or just the title itself... anyone could explain this?
especially the person who gave this code... thanks a lot
i found this code on this forum.. but im not satisfied on the results.. i tried to recode it but no luck.. i just need your opinions... if you can give example... many thanks...
Function searchTreeview(ByVal SearchString As String, ByVal Nodes As TreeNodeCollection, _
Optional ByVal ExactMatch As Boolean = False, _
Optional ByVal Recursive As Boolean = True) _
As TreeNode
Dim ret As TreeNode
For Each tn As TreeNode In Nodes
If ExactMatch = True Then
If tn.Text = SearchString Then Return tn
Else
If tn.Text.IndexOf(SearchString) <> -1 Then Return tn
End If
If Recursive = True Then
If tn.Nodes.Count > 0 Then
ret = searchTreeview(SearchString, tn.Nodes, ExactMatch, Recursive)
If Not ret Is Nothing Then Return ret
End If
End If
Next
Return Nothing
End Function
Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonSearch.Click
Dim tn As TreeNode = searchTreeview(TextBoxWordFind.Text, TreeViewBible.Nodes, False, True)
If Not tn Is Nothing Then
TreeViewBible.SelectedNode = tn
TreeViewBible.SelectedNode.BackColor = Color.RoyalBlue
TreeViewBible.SelectedNode.ForeColor = Color.White
Else
MsgBox("no match")
End If
End Sub
as i went through this code... im not getting the result i wanted... im confused what indexof really do...
on my treeview (for example only)
Old book
- Book 1 : Title One
- Book 2 : Title Two
- Chapter 1
- Chapter 2
- Paragraph 1
- Chapter 3
here is my scenario...
the color red text are from database... and the black one are only hard coded...
when i search for "Book 1".. no match
but when i search for "1" only... it founds it...
i need to search for the whole "Book 1"...
or just the title itself... anyone could explain this?
especially the person who gave this code... thanks a lot