How to Make a ComboBox in Visual Basic
- 1). Start Visual Basic and click the "New Project" link on the Start Page.
- 2). Double-click "Windows Forms Application," or click the selection once and click "OK" to create a blank form in a new project.
- 3). Scroll the cursor over the Toolbox tab on the top left of the Design Window to expand it. Double-click the "ComboBox" control, the "Button" control and the "TextBox" control to add these controls to the form. Click in the Design window to close the Toolbox.
- 4). Click on the ComboBox and scroll through the Properties window on the lower right of the Design window to "Items." Click the ellipsis box and enter several items in the resulting box, pressing "Enter" after each item to put each on its own line.
- 5). Double-click the "Button1" control on the form. You should see the following code in the Visual Basic Code Window:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
<cursor will appear here>
End Sub
Place the following line of code on the line before the "End Sub" line:
ComboBox1.Items.Add(TextBox1.Text)
This code causes the program to add the item you key into TextBox1 to the list in the ComboBox. - 6). Debug your program by clicking on the "Debug" menu item at the top of the screen. Enter an item in TextBox1 and click "Button1." Your new item should appear in the list when you click on the ComboBox1 drop-down arrow.
Source...