By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,504 Members | 2,618 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,504 IT Pros & Developers. It's quick & easy.

Can you search a listbox by a textbox value when the multiselect property isn't none?

P: 30
Currently I am able to use a texbox to search through the listbox only when the multiselect property is set to none. But when I change the property to simple or extended my function doesn't work. Please see below
Function
Expand|Select|Wrap|Line Numbers
  1. Public Function CheckListbox(strPass As String, lstPersons As ListBox)
  2.  
  3. Dim intCurrIndex As Integer
  4.  
  5. Dim intStringLen As Integer
  6.  
  7.  
  8.  
  9. intStringLen = Len(strPass)
  10.  
  11.  
  12.  
  13. For intCurrIndex = 0 To lstPersons.ListCount - 1
  14.  
  15.          If Left$(lstPersons.ItemData(intCurrIndex), intStringLen) = strPass Then
  16.  
  17.     Exit For
  18.  
  19.   End If
  20.  
  21. Next intCurrIndex
  22.  
  23.  
  24.  
  25. lstPersons = lstPersons.ItemData(intCurrIndex)
  26.  
  27.  End Function
Calling the function
Expand|Select|Wrap|Line Numbers
  1. Private Sub abSearchtbox_KeyPress(KeyAscii As Integer)
  2. Select Case KeyAscii
  3.  
  4.     Case Asc(" ") To Asc("z")
  5.  
  6.       strStringTyped = Me.abSearchtbox.Text & Chr(KeyAscii)
  7.  
  8.      Case 8
  9.          If strStringTyped > "" Then
  10.             strStringTyped = Left$(strStringTyped, Len(strStringTyped) - 1)
  11.         End If
  12. End Select
  13.  
  14.  
  15. CheckListbox strStringTyped, Me.allAddressBooklbox
  16.  
  17. End Sub
  18.  
I also tried another method but neither work when the multi select property is not none. I can't search at all.


Any Ideas??
Feb 15 '10 #1
Share this Question
Share on Google+
3 Replies


ADezii
Expert 5K+
P: 8,599
Hello xraive, I'm a little confused at to what you are trying to accomplish here. Please explain in detail, providing all relevant information.
Feb 15 '10 #2

P: 30
Sorry Adezii,

I currently have a listbox and would like to be able to search the records. I have a textbox setup so that when the user enters a key an item matching it in the listbox would be selected. This would be similar to the autoexpand feature on the combo box. I would like to be able to have a user type in a string and the first Item matching that string be selected from the listbox. I hope I made myself a little clear. I can attach a sample db of what I am doing if you like.


Thanks for your time ADezii
Feb 15 '10 #3

ADezii
Expert 5K+
P: 8,599
This should point you in the right direction:
Expand|Select|Wrap|Line Numbers
  1. Private Sub abSearchTBox_KeyPress(KeyAscii As Integer)
  2. Dim strStringTyped As String
  3. Dim intCurrIndex As Integer
  4. Dim intStringLen As Integer
  5.  
  6. 'Clear ALL Selections with each Keystroke
  7. For intCurrIndex = 0 To allAddressBooklbox.ListCount - 1
  8.   allAddressBooklbox.Selected(intCurrIndex) = False
  9. Next
  10.  
  11. strStringTyped = Me.abSearchTBox.Text
  12.  
  13. Select Case KeyAscii
  14.   Case Asc(" ") To Asc("z")
  15.     strStringTyped = strStringTyped & Chr(KeyAscii)
  16.   Case 8
  17.     If strStringTyped <> "" Then
  18.       strStringTyped = Left$(strStringTyped, Len(strStringTyped) - 1)
  19.     End If
  20.   Case Else
  21.     KeyAscii = 0        'CANCEL the Keystroke?
  22. End Select
  23.  
  24. intStringLen = Len(strStringTyped)
  25.  
  26. For intCurrIndex = 0 To allAddressBooklbox.ListCount - 1
  27.   If Left$(allAddressBooklbox.ItemData(intCurrIndex), intStringLen) = strStringTyped Then
  28.     allAddressBooklbox.Selected(intCurrIndex) = True
  29.       Exit For
  30.   End If
  31. Next intCurrIndex
  32. End Sub
  33.  
Feb 15 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.