AUTOCOMPLETACION EN COMBOS
Hola amiguitos
Desde hace varios días he tratado de realizar una autocompletación, es decir, que el usuario al ir digitando se vaya aproximando su búsqueda.
Lo mas cercano que he logrado es lo siguiente.
Private Sub ComboAuditor_KeyPress(KeyAscii As Integer)
If ComboAuditor.Text <> "" Then
ComboAuditor.Text = ComboAuditor.Text
SendKeys ("%{down}")
End If
EnviarEnterTab KeyAscii
End Sub
Pero sólo funciona desde el segundo caracter digitado.
Espero me puedan ayudar. Chao
Desde hace varios días he tratado de realizar una autocompletación, es decir, que el usuario al ir digitando se vaya aproximando su búsqueda.
Lo mas cercano que he logrado es lo siguiente.
Private Sub ComboAuditor_KeyPress(KeyAscii As Integer)
If ComboAuditor.Text <> "" Then
ComboAuditor.Text = ComboAuditor.Text
SendKeys ("%{down}")
End If
EnviarEnterTab KeyAscii
End Sub
Pero sólo funciona desde el segundo caracter digitado.
Espero me puedan ayudar. Chao
Te pongo un ejemplo a ver si te sirve, por cierto en mi
código el combo se llama Combo1.
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_SHOWDROPDOWN = &H14F
Private Const CB_GETDROPPEDSTATE = &H157
Private Const CB_FINDSTRING = &H14C
Private Sub Combo1_Change()
Dim lenOldText As String
lenOldText = Len(Combo1.Text)
Combo1.ListIndex = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal Combo1.Text)
Combo1.SelStart = lenOldText
Combo1.SelLength = Len(Combo1.Text)
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then
If SendMessage(Combo1.hwnd, CB_GETDROPPEDSTATE, 0, 0) = False Then
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, True, 0
Combo1.Text = ""
End If
If KeyAscii = 8 Then Combo1.Text = ""
End If
End Sub
código el combo se llama Combo1.
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_SHOWDROPDOWN = &H14F
Private Const CB_GETDROPPEDSTATE = &H157
Private Const CB_FINDSTRING = &H14C
Private Sub Combo1_Change()
Dim lenOldText As String
lenOldText = Len(Combo1.Text)
Combo1.ListIndex = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal Combo1.Text)
Combo1.SelStart = lenOldText
Combo1.SelLength = Len(Combo1.Text)
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then
If SendMessage(Combo1.hwnd, CB_GETDROPPEDSTATE, 0, 0) = False Then
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, True, 0
Combo1.Text = ""
End If
If KeyAscii = 8 Then Combo1.Text = ""
End If
End Sub
