LOCALIZAR NO COMBOBOX?

USUARIO.EXCLUIDOS 14/03/2005 07:58:29
#72877
Existe alguma forma de lacalizar registros no combobox apenas digitando as primeiras letras?

Valeu!!!!

THIAGO.CESAR 14/03/2005 08:07:19
#72879
Resposta escolhida
O combobox da biblioteca Microsoft Forms 2.0 já vem com o recurso. Mas existe um código muito bom para adaptar o combo normal, que foi postado nesse tópico pelo FGSANTOS. Vale a pena conferir.

AUTO COMPLETAR COMBO BOX
USUARIO.EXCLUIDOS 14/03/2005 09:07:13
#72890
 

Option Explicit

'===============================================================================
'
'===============================================================================
Private Sub CB_KeyUp(KeyCode As Integer, Shift As Integer)

Static NoSelectText As String ' texte tapé par l'utilisateur
Dim i As Long ' compteur de boucle
Const RGBerror = 255 ' couleur du fond en cas d'erreur


With CB '<== SEULE LIGNE A MODIFIER

' touche que l'on ne doit pas gérer dans cette procedure
If KeyCode = vbKeyUp Then Exit Sub ' utilisé par VB
If KeyCode = vbKeyDown Then Exit Sub ' utilisé par vb
If KeyCode = vbKeyLeft Then Exit Sub ' pour se déplacer
If KeyCode = vbKeyRight Then Exit Sub ' pour se déplacer

' action spécial pour la touche BACK
If KeyCode <> vbKeyBack Then
NoSelectText = Mid(.Text, 1, Len(.Text) - .SelLength)
Else
If NoSelectText <> "" Then
NoSelectText = Mid(NoSelectText, 1, Len(NoSelectText) - 1)
End If
End If

' recherche de la correspondance
For i = 0 To .ListCount - 1
If UCase(NoSelectText) = UCase(Mid(.List(i), 1, Len(NoSelectText))) Then
.ListIndex = i
Exit For
End If
Next

' selection de la partie que l'on a rajouté automatiquement
.SelStart = Len(NoSelectText)
.SelLength = Len(.Text)

' partie optionnelle qui change la couleur de fond en cas d'erreur
If .ListIndex = -1 Then
.BackColor = RGBerror
Else
.BackColor = vbWindowBackground
End If

End With

End Sub

'===============================================================================
'
'===============================================================================
Private Sub Form_Load()
With CB
.AddItem "Arthur"
.AddItem "Frederic"
.AddItem "Francois"
.AddItem "Francis"
.AddItem "Virginie"
.AddItem "Valery"
.AddItem "Viviane"
End With
End Sub

Tópico encerrado , respostas não são mais permitidas