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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo box

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
This is probbly a dumn question with an easy answer. What I want to is have a combo box such that it finds list items when the user start typing. For instance if in my combo box list I have the item 'Professional', as soon as the user start typing "Pro" the item starts to show up in the box. Thanks, I hope some one could help me out.
 
In the properties box of the cboBox find Style and click dropdown list and see if that does it.
 
try this code....

Option Explicit


Private Sub Form_Load()


With Combo1
.AddItem "ABCD"
.AddItem "ACDE"
.AddItem "ADEF"
.AddItem "AEFG"
.AddItem "ACFG"
.AddItem "AFGH"
.AddItem "AGHI"
End With
End Sub


Private Sub Combo1_KeyPress(KeyAscii As Integer)
Dim i As Long
Dim iNewStart As Integer
Dim strTemp As String
'Figure out the string prefix to search
' gor


If Combo1.SelStart = 0 Then
strTemp = Combo1.Text & Chr(KeyAscii)
Else
strTemp = Left(Combo1.Text, Combo1.SelStart) & Chr(KeyAscii)
End If
'Pass -1 as lParam to search entire list
'
i = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, strTemp)
'-1 return code indicates failure to fin
' d the string


If i <> -1 Then
'SendMessage returns the index of the fi
' rst occurrence
'of strTemp in the combo's list.
Combo1.Text = Combo1.List(i)
'Set the text selection appropriately fo
' r the
'suggested match
Combo1.SelStart = Len(strTemp)
Combo1.SelLength = Len(Combo1.List(i)) - Len(strTemp)
KeyAscii = 0
End If
End Sub

have nice programming.... :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top