AutoSearchCombo (2)




Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long

Public Const CB_FINDSTRING = &H14C

'(If you're using 16-bit VB, make the appropriate adjustments to

'the declare statement.)


'You'll need a static variable--one that remembers its value

'from each previous call to that subroutine or function--to

'keep track of how many characters you've entered in the combo

'box at any given time.


'Enter the following code in the combo box's Change event:


Private Sub Combo1_Change()
Dim iStart As Integer
Dim sString As String
Static iLeftOff As Integer

iStart = 1
iStart = Combo1.SelStart

If iLeftOff <> 0 Then
Combo1.SelStart = iLeftOff
iStart = iLeftOff
End If

sString = CStr(Left(Combo1.Text, iStart))

Combo1.ListIndex = SendMessage(Combo1.hwnd, _
CB_FINDSTRING, -1, ByVal CStr(Left( _
Combo1.Text, iStart)))

If Combo1.ListIndex = -1 Then
iLeftOff = Len(sString)
Combo1.Text = sString
End If

Combo1.SelStart = iStart
iLeftOff = 0
End Sub

'The static variable iLeftOff helps determine how many characters

'you need to use in the sString variable that you then pass to

'the API call.


'Run the application and notice how the cursor position stays

'at the proper position as you enter characters. The combo box

'displays a name if VB finds


'a match; otherwise, only the entered text appears. Una funzione di Autoricerca inserendo del testo in una ComboBox

Inserire questo codice in un Module Base










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