La Web del Programador: Comunidad de Programadores
 
    Pregunta:  8675 - MOSTRAR EL NOMBRE COMPLETO EN UN COMBOBOX O LISTCOMBO
Autor:  Sergio Arroyo
Tengo un combobox en un proyecto el cual, se llena al cargarse el formulario, usando additem.
Lo que necesito es, que cuando tiene el control el combo, a medida que se presiona una tecla valla mostrando, el nombre completo.
ejemplo: en el combo hay una palabra pedro, entonces cuando presiono la p en el combo me muestre la palabra pedro.

Desde ya muchas gracias.

  Respuesta:  José Ariel Limandri
Crea un formulario con un combo (combo1) y pegale esto

Option Explicit

Private Const CB_FINDSTRING = &H14C
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 Sub ComboChange(Combo As ComboBox)
Dim iStart As Integer
Dim sString As String
Static iLeftOff As Integer

iStart = 1
iStart = Combo.SelStart

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

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

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

Combo.SelStart = iStart

iLeftOff = 0
End Sub

Private Sub Combo1_Change()
ComboChange Combo1
End Sub

Private Sub Form_Load()
Combo1.AddItem "hola"
Combo1.AddItem "que"
Combo1.AddItem "tal"
End Sub

Dale F5 y suerte.