Sunday, April 4, 2010

VB6 Code - Procedure Auto Drop Down Pada Combobox

Di bawah ini merupakan procedure VB6 yang digunakan untuk membuat auto drop down pada objek ComboBox standar. Maksudnya, drop down otomatis apabila mouse berada di atasnya tanpa harus mengkliknya terlebih dahulu.
Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Const CB_SHOWDROPDOWN = &H14F

Public Sub AutoDropDown(cmb As ComboBox)
Call SendMessage(cmb.hwnd, CB_SHOWDROPDOWN, 1, ByVal 0&)
If cmb.ListIndex = -1 Then cmb.ListIndex = 0
End Sub
Contoh penggunaan proceder auto drop down pada combobox
Private Sub Combo1_GotFocus()
AutoDropDown Combo1
End Sub

Private Sub Form_Load()
With Combo1
.AddItem "asep hibban"
.AddItem "fahmi nurul anwar"
.AddItem "mohammad galbi"
.AddItem "karim wafi"
End With
End Sub