USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  Auto Completar (Combo)
RDM.TECNOLOGIA
SÃO PAULO
SP - BRASIL
Postada em 28/12/2006 11:08 hs            
Pessoal alguem tem um Exemplo de como fazer um auto completar em combo?
Tipo:
Popular a combo com nome de usuários e quando eu digitar as duas primeiras letras do nome ele se auto completa.
     
JOM
BOM JESUS DA LAPA
BA - BRASIL
ENUNCIADA !
Postada em 23/06/2007 11:32 hs            

Lançar na Combo

 

Private Sub combo1_KeyPress(KeyAscii As Integer)

   KeyAscii = Combo_AutoCompletar(combo1, KeyAscii)

End Sub

 

 

 

 

Lançar o Código abaixo em General Declarations:

 

Option Explicit

Private Const CB_FINDSTRING As Long = &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

Public Function Combo_AutoCompletar(xCombo As ComboBox, ByVal xKeyAscii As Long, Optional ByVal xUpperCase As Boolean = True) As Long

    Dim lngFind As Long, intPos As Long, intLength As Long, tStr As String

    With xCombo

        If xKeyAscii = 8 Then

            If .SelStart = 0 Then Exit Function

           

            .SelStart = .SelStart - 1

            .SelLength = Len(.Text)

            .SelText = vbNullString

        Else

            intPos = .SelStart

            tStr = .Text

            .SelText = (Chr$(xKeyAscii))

'            .SelText = IIf(xUpperCase, _

'                           UCase$(Chr$(xKeyAscii)), _

'                           LCase$(Chr$(xKeyAscii)))

        End If

        lngFind = SendMessage(.hwnd, CB_FINDSTRING, 0, ByVal .Text)

        If lngFind = -1 Then

            .Text = tStr

            .SelStart = intPos

            .SelLength = (Len(.Text) - intPos)

            Combo_AutoCompletar = xKeyAscii

        Else

            intPos = .SelStart

            intLength = Len(.List(lngFind)) - Len(.Text)

            .SelText = .SelText & Right$(.List(lngFind), intLength)

            .SelStart = intPos

            .SelLength = intLength

        End If

    End With

End Function

   
Página(s): 1/1    

CyberWEB Network Ltda.    © Copyright 2000-2025   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página