cmbAutoComplete




'Windows API/Global Declarations for :Autotype Combo Box

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Integer, _
ByVal lParam As Any) As Long
Public Const CB_FINDSTRING = &H14C
Private Sub Combo1_Change()
Dim i As Integer
Dim l As Long
Dim strNewText As String
'verifica se e' richiesta la ricerca automatica

If Not IgnoreTextChange And Combo1.ListCount > 0 Then
l = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, _
ByVal CStr(Combo1.Text))
strNewText = Combo1.List(l)
If Len(Combo1.Text) <> Len(strNewText) Then
' Trovato con Partial match

IgnoreTextChange = True
i = Len(Combo1.Text)
Combo1.Text = Combo1.Text & Mid$(strNewText, i + 1)
' Seleziona il testo auto-inserito

Combo1.SelStart = i
Combo1.SelLength = Len(Mid$(strNewText, i + 1))
End If
Else
' il Flag IgnoreTwextChange solo se ci sono modifiche

IgnoreTextChange = False
End If
End Sub

Private Sub Combo1_GotFocus()
' Seleziona un testo dalla combobox

Combo1.SelStart = 0
Combo1.SelLength = Len(Combo1.Text)
End Sub

Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
' Se l'user preme "Delete" il testo selezionato viene rimosso

If KeyCode = vbKeyDelete And Combo1.SelText <> "" Then
IgnoreTextChange = True
Combo1.SelText = ""
KeyCode = 0
End If
End Sub

Private Sub Combo1_KeyPress(KeyAscii As Integer)
' Se l'user preme "Backspace",

' Il testo selezionato viene rimosso

If KeyAscii = 8 Then
IgnoreTextChange = True
If Len(Combo1.SelText) Then
Combo1.SelText = ""
KeyAscii = 0
End If
End If
' Se l'user preme enter, seleziona il listindex

If KeyAscii = 13 Then
Combo1.ListIndex = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal CStr(Combo1.Text))
End If
End Sub











( cmbautocomplete.html )- by Paolo Puglisi - Modifica del 17/12/2023