How to add items to combo box control using API
Posted on July 7, 2010
Using API is one of way of adding items to combo box control. Using API is much faster comparing with regular add item method.
Instructions:
- Create a new Project
- Add a new Form to it and name it as Form1
- Add a combo box control to it and name it as combo1
- Add a command button control to it and name it as command1
Now, copy the following code to Form1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Option Explicit 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 Private Const CB_ADDSTRING = &H143 Private Sub Command1_Click() Dim sItem As String Dim I As Integer combo1.Clear For I = 1 To 5000 sItem = "Item number " & CStr(I) SendMessage combo1.hWnd, CB_ADDSTRING, 0, ByVal sItem Next End Sub |
This function uses SendMessage API function.
If you have any questions, please post as a comment. Thanks