|
-
Nov 5th, 2000, 05:19 AM
#1
Thread Starter
Junior Member
Hi.. I have applied this code for searching a specific string in a treeview.
The problem is that this code searches only the parent nodes
and I want to search everything...
Is it possible to suggest me any modifications or an entirely new approach?
Thanks in advance!
----------------------------------------------
Option Explicit
Public tvwSearch As TreeView
Dim iStart%
Dim iPass%
Private Sub cmdFind_Click()
Dim strToFind$, iIndex%
Dim blnFound As Boolean
strToFind = LCase$(txtFind)
With tvwSearch
'check not on child node and an item selected
If .SelectedItem Is Nothing Then
iStart = 1
.SelectedItem = .Nodes(iStart)
ElseIf Not .SelectedItem.Parent Is Nothing Then
iStart = .SelectedItem.Parent.Index
Else
iStart = .Nodes(.SelectedItem.Index).Next.Index
End If
LOOKAGAIN:
Screen.MousePointer = vbHourglass
iIndex = iStart
'loop through nodes looking for the text
Do
'check for matching whole entry
If chkWhole Then
'match all of entry
If .Nodes(iIndex) = strToFind Then blnFound = True
Else
'match part entry
If LCase$(.Nodes(iIndex)) Like "*" & strToFind & "*" Then blnFound = True
End If
If blnFound Then
.SelectedItem = .Nodes(iIndex)
.Nodes(.SelectedItem.Index).EnsureVisible
cmdFind.Caption = "&Find Next"
Screen.MousePointer = vbDefault
Exit Sub
End If
iIndex = .Nodes(iIndex).Next.Index
Loop While Not iIndex = .Nodes(iStart).LastSibling.Index
Screen.MousePointer = vbDefault
'If we started lower down the tree and haven't found the string
If Not blnFound And iPass = 0 Then
'see if user wants to search from top of tree
If MsgBox(strToFind & " was not found." & vbCrLf & "Search from beginning?", _
vbQuestion + vbYesNo, "Not Found") = vbNo Then
.SelectedItem = .Nodes(iStart)
Unload Me
Exit Sub
End If
'select first node and search again
iStart = 1
iPass = 1
Goto LOOKAGAIN
Else
'notify user that text not found
MsgBox strToFind & " was not found.", vbInformation, "Not Found"
cmdFind.Caption = "&Find"
iPass = 0
iStart = 0
txtFind.SetFocus
txtFind.SelStart = 0
txtFind.SelLength = Len(txtFind)
End If
End With
End Sub
Private Sub Form_Load()
iStart = 0
iPass = 0
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|