View Full Version : Sleeper: Filter ListBox Items
sheeeng
06-08-2005, 09:49 PM
Hello all! :hi: :hi:
How do I filter the data in ListBox1 using text entered in TextBox1?
eg. enter "o" will focus on first string start with "o" in ListBox.
Thanks. :friends:
:beerchug:
Jacob Hilderbrand
06-09-2005, 01:35 PM
Try something like this.
Private Sub CommandButton1_Click()
Dim i As Long
Dim n As Long
Dim Str As String
Str = Me.TextBox1.Text
n = Me.ListBox1.ListCount
For i = 0 To n - 1
If Left(Me.ListBox1.List(i), Len(Str)) = Str Then
Me.ListBox1.ListIndex = i
Exit Sub
End If
Next i
End Sub
You could also put this code on the change event for the TextBox.
Private Sub TextBox1_Change()
Dim i As Long
Dim n As Long
Dim Str As String
Str = Me.TextBox1.Text
n = Me.ListBox1.ListCount
For i = 0 To n - 1
If Left(Me.ListBox1.List(i), Len(Str)) = Str Then
Me.ListBox1.ListIndex = i
Exit Sub
End If
Next i
End Sub
sheeeng
06-09-2005, 07:29 PM
Thanks, Killian!
:hi: :friends:
Is there anywhere that I can focus that filtered data at the uppermost part of that region?
eg. Type 'o' in tb.
ListBox1 (requirement that i need) :help
......
orange <-----
mango
apple
......
this type is ur code output, very good! :thumb
(but not I want to implement :( )...
ListBox1
.......
apple
mango
orange <-----
........
Thanks. Anyone can help?
Or a better idea here...Filter and show only those data start with 'o' (example on top)
ListBox1 (only show two data [all with o] in the listbox)
orange <-----
oxygen
thanks.:hi: :beerchug:
sheeeng
06-13-2005, 08:21 PM
Can anyone have other ideas on implement filter options on Userform1.ListBox1 ? My seems not working....
Thanks.
xCav8r
06-13-2005, 08:35 PM
If you have Visual Studio tools for MS Office, then it would be easier to do what you'd like to do. If not, the easiest workaround that I see is to convert your listbox to a combobox, since you want combobox behavior on your listbox.
It might not look as good, but functionality always outweighs aesthetics--unless you're doing work for graphic designers. ;)
sheeeng
06-13-2005, 09:33 PM
functionality always outweighs aesthetics
Thanks for helping. :hi: Now i know a more bout functionality. :thumb
sheeeng
06-16-2005, 10:54 PM
Thanks, Killian!
:hi: :friends:
Is there anywhere that I can focus that filtered data at the uppermost part of that region?
eg. Type 'o' in tb.
ListBox1 (requirement that i need) :help
......
orange <-----
mango
apple
......
this type is ur code output, very good! :thumb
(but not I want to implement :( )...
ListBox1
.......
apple
mango
orange <-----
........
Thanks. Anyone can help?
Or a better idea here...Filter and show only those data start with 'o' (example on top)
ListBox1 (only show two data [all with o] in the listbox)
orange <-----
oxygen
thanks.:hi: :beerchug:
Sorry for posting again. I really need to know how to filter the ListBox (the selected first data at the top of list box)?
Does anyone have ideas?
Can share with me? :doh:
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.