-
Apr 11th, 2010, 09:36 AM
#1
Thread Starter
Member
[RESOLVED] check if combobox item contains a string
Hello guys. I would like to know if there is a code to check if a combobox item contains a string and then display only the combobox items that contain the string (like webbrowsers do with the adress combobox). I have found some solutions using instr but I would like someone to help me display these items in combobox (how to make them visible) Here is some code:
Code:
Private Sub Combo1_KeyPress(KeyAscii As Integer)
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, True, ByVal 0
Dim i As Integer
For i = 0 To Combo1.ListCount - 1
'the code i need
Next i
End Sub
-
Apr 11th, 2010, 10:09 AM
#2
Re: check if combobox item contains a string
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Apr 11th, 2010, 01:26 PM
#3
Thread Starter
Member
Re: check if combobox item contains a string
Thanks for your reply, but that's not what I'm saying. I want to have a code to display the combobox items i want. Have a look at the folowing code:
Code:
Option Explicit
Private Const CB_SHOWDROPDOWN = &H14F
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
'I have developed the code viewing by akhileshbc's links
Private Sub AdressBar_KeyDown(KeyCode As Integer, Shift As Integer)
Dim i As Integer
Dim Found
Select Case KeyCode
Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown, vbKeyShift, vbKeyEscape, vbKeyPageUp, vbKeyPageDown, vbKeyControl
Exit Sub
Case Else
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, True, ByVal 0
For i = 0 To Combo1.ListCount - 1
found = InStr(1, AdressBar.List(i), AdressBar.Text, vbBinaryCompare)
If found <> 0 Then
'display these item
Next i
End Select
End Sub
-
Apr 11th, 2010, 05:07 PM
#4
Re: check if combobox item contains a string
To show only the matching items, remove everything that doesn't match.
To do that, replace this:
Code:
For i = 0 To Combo1.ListCount - 1
found = InStr(1, AdressBar.List(i), AdressBar.Text, vbBinaryCompare)
If found <> 0 Then
'display these item
Next i
...with this:
Code:
For i = Combo1.ListCount - 1 To 0 Step -1
found = InStr(1, AdressBar.List(i), AdressBar.Text, vbBinaryCompare)
If found = 0 Then
AdressBar.Remove i
End If
Next i
However, this will clearly reduce the amount of items each time - so if the amount of characters in AdressBar.Text reduces (or one or more of the characters in it are changed), you will need to re-load the list before re-running this loop.
-
Apr 12th, 2010, 08:53 AM
#5
Thread Starter
Member
Re: check if combobox item contains a string
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
|