Membuat Auto Complete Pada Combo box

    Share

    eRGe@N5
    Member Newbie
    Member Newbie

    Male
    Thread & Post : 14
    Point Forum : 207033
    Thanks Given : 0
    Join date : 02.08.11
    Age : 27
    Lokasi : N3 & N5

    default Membuat Auto Complete Pada Combo box

    Post by eRGe@N5 on Thu Aug 18, 2011 1:48 am

    •Buatlah Project Baru Standart Exe
    •Tambahkan 1 buah ComboBox Style : Dropdown Combo
    •Tambahkan 1 buah Module

    'Ketik Coding berikut pada Module

    Spoiler:
    Option Explicit

    Const CB_FINDSTRING = &H14C

    Public 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 Enum EnumKarakter
    Asli = 0
    Ubah = 1
    End Enum

    Public Function AutoComplete( _
    cbCombo As ComboBox, _
    sKeyAscii As Integer, _
    Optional bUpperCase As Boolean = True, _
    Optional cCharacter As EnumKarakter = Asli) _
    As Integer
    Dim lngFind As Long, intPos As Integer
    Dim intLength As Integer, tStr As String
    With cbCombo
    If sKeyAscii = 8 Then
    If .SelStart = 0 Then Exit Function
    .SelStart = .SelStart - 1
    .SelLength = 32000
    .SelText = ""
    Else
    intPos = .SelStart
    tStr = .Text
    If bUpperCase = True Then
    .SelText = UCase(Chr(sKeyAscii))
    Else
    .SelText = (Chr(sKeyAscii))
    End If
    End If

    lngFind = SendMessage(.hwnd, CB_FINDSTRING, 0, _
    ByVal .Text)
    If lngFind = -1 Then
    Exit Function
    Else
    intPos = .SelStart
    intLength = Len(.List(lngFind)) - Len(.Text)
    If cCharacter = Ubah Then
    .SelText = .SelText & Right(.List(lngFind), _
    intLength)
    Else
    .Text = .List(lngFind)
    End If
    .SelStart = intPos
    .SelLength = intLength
    End If
    End With
    End Function

    ' Ketik Coding diberikut pada Form

    Option Explicit

    Private Sub Combo1_KeyPress(KeyAscii As Integer)
    KeyAscii = AutoComplete(Combo1, KeyAscii, False, Asli)
    End Sub

    Private Sub Form_Load()
    Call AddData
    End Sub

    Private Sub AddData()
    With Combo1
    .Clear
    .AddItem "Ana Lestari"
    .AddItem "Budi Setiawan"
    .AddItem "Eka Syahputra"
    .AddItem "Wahyu Perdana"
    .AddItem "Blog walking"
    .AddItem "Terserah"
    End With
    End Sub

    Kemudian Run (jalankan) Program atau tekan F5, lalu pada combobox coba ketik huruf a , maka secara Otomatis teks pada combobox akan menjadi Ana Lestari. Semoga Tip ini ada mamfaat nya bagi kita semua, dan jangan lupa nitip komennya ya, terimakasih sebelumnya ... salam

      Waktu sekarang Thu Dec 08, 2016 10:51 am