|
-
Jul 14th, 2001, 11:25 PM
#1
searching a treeview
is it possible to do a search in a treewview like you do in notepad. say I click on search and an input box comes up and you type in your word/s and push search and have it highlight the searched word in the treeview then hit f3 to keep searching?
if so how would I proceed? I can do the input box but not sure on how or if I can do the f3 part of it.
thanks in advance
-
Jul 16th, 2001, 06:36 AM
#2
-= B u g S l a y e r =-
search sample :
Code:
Private Sub Command1_Click()
Dim l As Long
Dim n As Node
Dim sSearchString As String
sSearchString = "test"
For l = 1 To TreeView1.Nodes.Count
Set n = TreeView1.Nodes(l)
If UCase(n.Text) = UCase(sSearchString) Then
n.Selected = True
'or call the click event : TreeView1_NodeClick n
Exit For
End If
Next l
End Sub
-
Jul 16th, 2001, 07:05 AM
#3
Frenzied Member
you can half search time by UCASEing the search string only once:
Code:
Private Sub Command1_Click()
Dim l As Long
Dim n As Node
Dim sSearchString As String
sSearchString= UCase("test")
For l = 1 To TreeView1.Nodes.Count
Set n = TreeView1.Nodes(l)
If UCase(n.Text) = sSearchString Then
n.Selected = True
'or call the click event : TreeView1_NodeClick n
Exit For
End If
Next l
End Sub
and you can half the search time again by using
Option Compare Text
Code:
Option Compare Text
Private Sub Command1_Click()
Dim l As Long
Dim n As Node
Dim sSearchString As String
sSearchString= test"
For l = 1 To TreeView1.Nodes.Count
Set n = TreeView1.Nodes(l)
If n.Text = sSearchString Then
n.Selected = True
'or call the click event : TreeView1_NodeClick n
Exit For
End If
Next l
End Sub
-
Jul 16th, 2001, 07:16 AM
#4
-= B u g S l a y e r =-
Mark, what does Option Compare Text do ?
-
Jul 16th, 2001, 07:21 AM
#5
Frenzied Member
Option Compare Text makes text comparisons case insensitive
-
Jul 16th, 2001, 07:23 AM
#6
-= B u g S l a y e r =-
thanks, I feel a bit stupid now
-
Jul 17th, 2001, 10:03 AM
#7
thnaks guys I will play with that and let you know.
-
Jul 17th, 2001, 02:05 PM
#8
ok, I played with it and found out that I have to have the exact text case to get any results. plus how do I make it search child nodes instead of parent ones?
also what/where do I put that option campare text, can it co-exist with option explicit
-
Jul 17th, 2001, 02:17 PM
#9
-= B u g S l a y e r =-
doesnt the sample search the child nodes ?
-
Jul 17th, 2001, 02:19 PM
#10
-= B u g S l a y e r =-
and yes
Code:
Option Explicit
Option Compare Text
is not a porblem
-
Jul 17th, 2001, 02:28 PM
#11
I put it under option explicit and I get a compile error saying
"Expected: Base or Compare or Explicit or Private."
and it highlights Compare
well I guess it does search child nodes. forgot that my treeview was under a parent. but how do I make it search the child of the child then.
-
Jul 17th, 2001, 02:30 PM
#12
-= B u g S l a y e r =-
Originally posted by scoutt
...that option campare text, can it co-exist with option explicit
think you just misspelled compare ? 
anyway that would create the error you reported.
-
Jul 17th, 2001, 02:33 PM
#13
-= B u g S l a y e r =-
well I guess it does search child nodes. forgot that my treeview was under a parent. but how do I make it search the child of the child then.
the code sample should search for all nodes, child and child of a child and child of childs child.... I'd better stop
-
Jul 17th, 2001, 02:45 PM
#14
well crap I did misspell it. thanks.
ok I can search child of the child of the child, but the reason I didn't was becasue it had to be spelled exactly like the text I was searching for. I tried
VB Code:
If UCase(n.Text) = UCase("'*sSearchString*'")
I don't get any errors but then again it didn't do anything different
what other way can I do it so it doesn't matter what the text that I am searching for it goes to it.
then when I found something, how do I make it continue with the same work like the f3 does in notepad search
-
Jul 17th, 2001, 02:55 PM
#15
-= B u g S l a y e r =-
hmm try this for the *sdfasdf search 
Code:
Option Compare Text
Private Sub Command1_Click()
Dim l As Long
Dim n As Node
Dim sSearchString As String
sSearchString= test"
For l = 1 To TreeView1.Nodes.Count
Set n = TreeView1.Nodes(l)
If InStr(1, n.Text, sSearchString, vbUseCompareOption) Then
n.Selected = True
'or call the click event : TreeView1_NodeClick n
Exit For
End If
Next l
End Sub
-
Jul 17th, 2001, 03:08 PM
#16
I get an variable not defind error on the vbUseCompareOption
-
Jul 17th, 2001, 03:19 PM
#17
-= B u g S l a y e r =-
oops.. sorry about that, use vbTextCompare instead of vbUseCompareOption
-
Jul 17th, 2001, 03:21 PM
#18
-= B u g S l a y e r =-
Ok my friend ... this is it:
Create a new project,
Add a treeview and a commandbutton
paste this code into your form:
Code:
Option Explicit
Private s As String
Private lLastNodeFound As Long
Private Sub Command1_Click()
If Command1.Caption = "Find" Then s = InputBox("What do want to search for?")
If s <> "" Then
If SearchTree(s) Then
Command1.Caption = "Find next"
Else
MsgBox "Reached the end..."
Command1.Caption = "Find"
End If
End If
End Sub
Private Sub Form_Load()
Dim n As Node
Set n = TreeView1.Nodes.Add(, , , "Settings...")
TreeView1.Nodes.Add n, tvwChild, "Desktop", "Desktop settings"
TreeView1.Nodes.Add n, tvwChild, "Mouse", "Mouse pointer settings"
TreeView1.Nodes.Add n, tvwChild, "Misc", "Misc"
Set n = TreeView1.Nodes.Add(, , , "Test...")
TreeView1.Nodes.Add n, tvwChild, "Desktop2", "Desktop settings"
TreeView1.Nodes.Add n, tvwChild, "Mouse2", "Mouse pointer settings"
TreeView1.Nodes.Add n, tvwChild, "Misc2", "Misc"
Command1.Enabled = True
Command1.Caption = "Find"
End Sub
Private Function SearchTree(sSearchString As String) As Boolean
Dim l As Long
Dim n As Node
'Dim sSearchString As String
For l = lLastNodeFound + 1 To TreeView1.Nodes.Count
Set n = TreeView1.Nodes(l)
If InStr(1, n.Text, sSearchString, vbTextCompare) Then
n.Selected = True
SearchTree = True
lLastNodeFound = l
'or call the click event : TreeView1_NodeClick n
Exit Function
End If
Next l
SearchTree = False
lLastNodeFound = 0
End Function
*phuuu...* that should do it
-
Jul 17th, 2001, 03:23 PM
#19
PowerPoster
This is some pretty handy code.
-
Jul 17th, 2001, 03:24 PM
#20
I took out the vbUseCompareOption variable and it works pretty good. but after it finds something then it just quits searching. how can i continue it?
I was thinking of just looping back to the begining but wouldn't that just keep going by itself?
-
Jul 17th, 2001, 03:25 PM
#21
-= B u g S l a y e r =-
try the sample...
-
Jul 17th, 2001, 03:26 PM
#22
PowerPoster
are you telling that to me or to scoutt?
-
Jul 17th, 2001, 03:29 PM
#23
-= B u g S l a y e r =-
-
Jul 17th, 2001, 03:30 PM
#24
-= B u g S l a y e r =-
Originally posted by eiSecure
are you telling that to me or to scoutt?
scoutt
-
Jul 17th, 2001, 03:31 PM
#25
PowerPoster
-
Jul 17th, 2001, 03:34 PM
#26
-= B u g S l a y e r =-
uh.. my ears...
sorry eiSec...ure its my rheumatism preventing me from writing those loooong nicks
-
Jul 17th, 2001, 03:35 PM
#27
-
Jul 17th, 2001, 03:40 PM
#28
sorry peet, I didn't see your post. blind as a bat I guess. I wil try that and let you know.
eiSecure: yes it is pretty handing if I can get my hands and eyes to work together,
-
Jul 17th, 2001, 03:43 PM
#29
-= B u g S l a y e r =-
...pretty handing if I can get my hands and eyes to work
oooops.... careful or eiSec will smack you as well
-
Jul 17th, 2001, 03:45 PM
#30
PowerPoster
can you not read the size 72 text I wrote????
its eiSecur!!!!!!!!!!
-
Jul 17th, 2001, 03:46 PM
#31
PowerPoster
wait, sorry. Typo.
its: eiSecure!!!
-
Jul 17th, 2001, 03:47 PM
#32
-= B u g S l a y e r =-
Originally posted by eiSecure
can you not read the size 72 text I wrote????
its eiSecur!!!!!!!!!!
heeh.... got you !!
eiSecur eh ??
-
Jul 17th, 2001, 03:54 PM
#33
PowerPoster
no no no no no!
....now you're gonna haunt me with that the rest of my live on this forum, aren't you??
-
Jul 17th, 2001, 04:07 PM
#34

ok you guys, I did noticed that I made a boo boo, didn't feel like editing it.
I want to thank you peet that last sample worked almost like I wanted. I can play with it and get it exact.
thanks peet and eiSecure spelled right too
-
Jul 17th, 2001, 04:07 PM
#35
-= B u g S l a y e r =-
yes yes yes ...
-
Jul 17th, 2001, 04:09 PM
#36
PowerPoster
man, you're getting too excited over this...
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
|