PDA

Click to See Complete Forum and Search --> : Finding list item as u typed in combo box(Dropdown List style).


jpark
Nov 15th, 1999, 07:22 AM
Basically the title say it all.

When I type a letter in combo box it finds item by matching the letter that I typed, but when I type in a second letter it searchs item that starts with the second letter.

I wonder is there a way to macthing list item as u typed in combo box(Dropdown List style).

Thanks in advance.
Joon

AlanTodd
Nov 15th, 1999, 07:50 AM
I am using a Combo Box in an application with the Style property set to 1. This is a simple Combo Box, not a drop down.

This means it takes more screen real estate, but I have it on o pop up window and it works fine.

Serge
Nov 15th, 1999, 08:44 AM
Read the Previous Post (http://www.vb-world.net/ubb/Forum1/HTML/010502.html)


Regards,

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)

jpark
Nov 16th, 1999, 12:29 AM
Serge, it's not work for dropdown list combo box.

I tried ur code for change events, which won't trigger when I type in combobox, and keydown events, but it didn't work. :(

It's not a big deal, but would be nice if I can use that feature :)

Thanks
Joon

David Laplante
Nov 16th, 1999, 12:37 AM
Jpark...

try this post http://www.vb-world.net/ubb/Forum1/HTML/010330.html

[This message has been edited by David Laplante (edited 11-16-1999).]

jpark
Nov 16th, 1999, 02:09 AM
Thanks David,

But I tried that already.

It probably works fine with combo box style-0(Dropdown Combo), but doesn't work with style-2(Dropdown list).

I get run-time error '380', which is Invalid property value for Combo1.SelStart.

Joon

Aaron Young
Nov 16th, 1999, 02:43 AM
Try this:

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
Private Const CB_FINDSTRING = &H14C

Private Sub Combo1_KeyPress(KeyAscii As Integer)
Static sTyped As String
Dim iIndex As Integer
sTyped = sTyped & Chr(KeyAscii)
iIndex = SendMessage(Combo1.hwnd, CB_FINDSTRING, 0, ByVal sTyped)
If iIndex > -1 And KeyAscii <> vbKeyDelete And KeyCode <> vbKeyBack Then
Combo1 = Combo1.List(iIndex)
Else
sTyped = ""
KeyAscii = 0
End If
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

jpark
Nov 16th, 1999, 04:38 AM
Hi Aaron,

I don't get any error from ur code, but still dosen't work the way I wanted to be.

It only matches first character of item list.
If I type "VS" it finds item that starts with letter "V" then finds item that starts with "S" ignoring letter "V".

I want to find items that has "VS", when I type "VS".

Thanks for replies.
Joon

pavinda
Nov 16th, 1999, 04:53 AM
Try This Procedure. I used it in my project.
It's really work.
Sub Gs_ComboPress(cboCombo As Control, vKeyAscii)
'=================================================
'Function : Use show value of combo (deafault) when press any key.(Ascii)
'Comment : Use procedure at event "keypress"
'=================================================
Dim cboComboTxt As String, xlen%, i%
cboCombo.SelText = ""
cboComboTxt = cboCombo.Text & Chr(vKeyAscii)
xlen = Len(cboComboTxt)
For i = 0 To cboCombo.ListCount - 1
If Len(cboCombo.List(i)) >= xlen Then
If UCase(Left(cboCombo.List(i), xlen)) = UCase(cboComboTxt) Then
cboCombo.Text = cboCombo.List(i)
cboCombo.SelStart = xlen
cboCombo.SelLength = Len(cboCombo.List(i)) - xlen
Exit For
End If
End If
Next
If vKeyAscii >= 45 Then
vKeyAscii = 0
End If
End Sub

jpark
Nov 16th, 1999, 06:03 AM
Hi pavinda,

I'm using combo box style-2(Dropdown List), which accept only text that are already in the combo list, and I don't think u can set the SelStart property to certain number in this style of combo box

To make combo box be empty,I have to do like this [cboCombo.ListIndex = -1] but not like this [cboCombo.SelText = ""]

Thanks anyway
Joon

Aaron Young
Nov 16th, 1999, 08:25 AM
Are you sure you pasted the code I posted exactly?

I'm using it here and it works exactly as you want it to, with the Combobox Style Set to DropDown List.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

jpark
Nov 17th, 1999, 12:09 AM
Hi Aaron,

Yes, I copied exactly what u posted here, except that I changed "KeyCode" to "KeyAscii"

Ur code worked as long as there r no items in the list that starts with second letter of what I typed in the combo box.

For example, if there r "vs7" and "sc-7" in the list, it would bring up "sc-7" when I type "vs".

I guess I'll have to change style of combo box. I use combo box dropdown list style, so that users don't accidently input wrong model since this style won't accept other than what's in the list.

I just didn't want to go through whole list to make sure it's in the list every time user input models.

On the other hands, by using dropdown list, users having a hard time for selecting models cuz there r a lot of models.

Thanks
Joon

Aaron Young
Nov 17th, 1999, 02:41 AM
I see what's happening.. In order for this type of routine to work, your list needs to be sorted.

Set the Sorted Property to True at Design Time.

P.S. KeyCode was a Typo on my part.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

jpark
Nov 17th, 1999, 06:46 AM
Ur right Aaron.
It works fine except one.

I type "VS", and then I realize that it wasn't model that I want it and type "KD",
It then matches item that starts with "D" by missing one character.

I modified ur code a little by giving option to erase content when user type in wrong and by emptying the box when there r no matched item

Public Sub GetItemInComboBox(parCombo As ComboBox, parKeyAscii As Integer)

Static sTyped As String
Dim iIndex As Integer

If parKeyAscii = vbKeyBack Then
sTyped = ""
parKeyAscii = 0
Else
sTyped = sTyped & Chr(parKeyAscii)
End If

iIndex = SendMessage(parCombo.hwnd, CB_FINDSTRING, 0, ByVal sTyped)
If iIndex = -1 Then
parCombo.ListIndex = -1
ElseIf iIndex > -1 Then
parCombo = parCombo.List(iIndex)
Else
sTyped = ""
parKeyAscii = 0
End If

End Sub

By the way, have u noticed that the KeyPress event won't recognize "Delete" key, one that next to End key, it detects "Del" with dot key as VbKeyDelete.

U can use the VbKeyDelete constant to catch the "Delete" key in KeyUp and KeyDown events.

Thanks again all who replied to my question, especially Aaron :)

Joon