Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListBox (please help)!!

Status
Not open for further replies.

valjah

Programmer
Aug 1, 2005
11
I am using a list box to display several items. I want to use this so that when user enters a letter say A. All the items that starts with A are displayed. This work, however if the user enters App, i would like all items that start with app be dsiplayed. How do I do thsi? Is the list box the best thing to used. I tried the combo box but this box does not display all the items at once and only display the item as it is typed. Any help will be appreciated.

Thanks in advanced
 
If you specifically want to use a listbox you could:
1. Create two listboxes on your form
e.g. lstFullData and lstFilteredData
2. Set lstFullData.Visible = False
3. Set lstFilteredData.Sorted = True
4. Add a Search textbox, e.g. txtSearch
5. At runtime, fill lstFullData with all values

Then
Code:
Private Sub txtSearch_Change()

Dim intX As Integer

lstFilteredData.Clear
For intX = 0 To lstFullData.ListCount - 1
   If lstFullData.List(intX) Like txtSearch.Text & "*" Then
      lstFilteredData.AddItem List1.List(intX)
   End If
Next

End Sub
Note that this method is case sensitive, to ignore case change
Code:
If lstFullData.List(intX) Like txtSearch.Text & "*" Then
to
Code:
If UCase(lstFullData.List(intX)) Like UCase(txtSearch.Text) & "*" Then
 
Thanks for this response. I am using vb 6.3. when I try to use .list on the list box. I am getting that the "method or data member is not found". Also in your example what is List1.List(intX). Where is this defined.


 
Looks like VBA to me! This forum is specific to VB5/6. Check out faq222-2244 to see how to get the best from these forums - paragraph 3 covers choice of forum. General VBA is dealt with in forum707, but if this is Access specific there are several dedicated Access forums (use the Find a Forum facility at the top of the page)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Oops, my mistake
Code:
lstFilteredData.AddItem List1.List(intX)
should be
Code:
lstFilteredData.AddItem lstFullData.List(intX)
Trevor
 
Considering how many times I've seen this type of question asked in this forum as well as the Javascript forum and the ASP forum, I wonder why MS and others do not make this a standard attribute for their select boxes and list boxes. If anyone from MS is listening: "Please!"

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
I use this to do the same thing in a data grid. Maybe this could be adapted:

datPatients.RecordSource = "SELECT * FROM [P_demo_T] WHERE [P_last] LIKE '" & mylast & "%' ORDER BY [P_last], [P_first]"


Shannan

 
I have a form (Form1) with a listbox on it (ListBox1). The listbox gets it rowsource from Groups(a defined name range with the worksheet). I have the listbox set to SelectMulti. All I want is when I select 2 or more items, and click Button1, for the values selected to be placed in a cell (D45) and have each value separated by a comma. Since I know very litte about VB this is probably a simple question for someone!

Thanks so much in advance.

David
 
David,

read johnwm 's 18 Aug 05 3:43 post first and post your question at VBA Visual Basic for Applications (Microsoft) forum707
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top