Se poi unisci i due suggerimenti che hai avuto da Oregon e Brainjar, avrai l'espansione e la selezione del termine in base alla prima lettera inserita, come segue:
codice:
Option Explicit
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
Const CB_SHOWDROPDOWN = &H14F
Const CB_ERR = (-1)
Const CB_FINDSTRING = &H14C
' Carica la ComboBox ed inserisce il termine dalla prima lettera:
Private Sub Form_Load()
Combo1.AddItem "French fries"
Combo1.AddItem "Hamburgers"
Combo1.AddItem "Milkshakes"
Combo1.AddItem "Onion rings"
Combo1.AddItem "Ice"
Combo1.AddItem "Ice cream"
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
Dim CB As Long
Dim FindString As String
If KeyAscii < 32 Or KeyAscii > 127 Then Exit Sub
If Combo1.SelLength = 0 Then
FindString = Combo1.Text & Chr$(KeyAscii)
Else
FindString = Left$(Combo1.Text, Combo1.SelStart) & Chr$(KeyAscii)
End If
CB = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal FindString)
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 1, 0
If CB <> CB_ERR Then
Combo1.ListIndex = CB
Combo1.SelStart = Len(FindString)
Combo1.SelLength = Len(Combo1.Text) - Combo1.SelStart
End If
KeyAscii = 0
End Sub