Como autocompletar un combobox

Adrian
20 de Julio del 2004
Amigos, alguien que por favor me pueda ayudar, en VB6.0 quiero que mientras se vaya escribiendo en un combobox se vaya autocompletando con las coincidencias. Gracias a todos

RIGEL CEDE?
20 de Julio del 2004
aqui les va el codigo para autocompletar el combobox
se necesita un combo, un text y dos command buttons

Private lastDelOp As Boolean

Private Sub Combo1_Change()
\'change made by me flag
Static ChangeFlag As Boolean

\'if change is made by the user
If Not ChangeFlag Then

Dim cboText As String
Dim lencboText As Integer
Dim tmpLen As Integer
Dim tmp As Integer

\'init variables
cboText = Combo1.Text
lencboText = Len(Combo1.Text)

\'if the last operation has not been deletion
If Not lastDelOp Then

\'check if user entry matches an item
For tmp = 0 To Combo1.ListCount - 1
If UCase(Left(Combo1.Text, Combo1.SelStart)) = UCase(Combo1.List(tmp)) Then
\'the change that follows is made by me, so set flag
ChangeFlag = True
Combo1.Text = Combo1.List(tmp)
Combo1.SelStart = Len(Combo1.Text)
\'reset flag
ChangeFlag = False
\'reset deltion operation flag
lastDelOp = False
Exit Sub
End If
Next tmp

\'if you omit this check, when you delete the text in
\'the cbobox the first item will be automaticall
\'displayed
\'if not just cleared
If lencboText > 0 Then
\'loop to check all items
For tmp = 0 To Combo1.ListCount - 1
\'if fisrt letters of current item match the cbotext
\'if you omit ucase the search will be case sensitive
If UCase(Left(Combo1.List(tmp), lencboText)) = UCase(cboText) Then
\'save entered text length
tmpLen = lencboText
\'set new text - the cbobox item
ChangeFlag = True
Combo1.Text = Combo1.List(tmp)
\'select all letters after those the user entered
Combo1.SelStart = tmpLen
Combo1.SelLength = Len(Combo1.List(tmp)) - tmpLen
ChangeFlag = False
\'exit the loop
Exit For
End If
Next tmp
End If \'lencboText > 0

End If \'Not lastDelOp
\'reset flag
lastDelOp = False
End If \'Not ChangeFlag
End Sub

Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
\'if delete or backspace pressed - pull up flag
If (KeyCode = vbKeyDelete) Or (KeyCode = vbKeyBack) Then
lastDelOp = True
End If
End Sub

Private Sub botonborrar_Click()
If Combo1.ListIndex <> -1 Then
Combo1.RemoveItem Combo1.ListIndex
End If
End Sub

Private Sub botonagregar_Click()
X = Combo1.AddItem(Text1.Text)
Text1.Text = ""
Combo1.List X
End Sub

espero y le entiendan
=)