How to Display the First Item in the ComboBox Drop-down List in Visual Basic
Dynamically displaying the first item in a combo box control can make your application more user friendly by showing an item in the control when your application loads. Programmers commonly add items to a combo box at startup, but they fail to display the first item, which makes the control look empty. In Visual Basic you can use the Text property and the Items property to display the first item.
Instructions
-
-
1
Launch Microsoft Visual Basic Express, click "New Project" on the left pane of your computer screen and double-click "Windows Forms Application" to create a new project.
-
2
Double-click "ComboBox" on the Toolbox pane to create a new combo box control.
-
-
3
Double-click the form to create a new Load event procedure and add the following code to populate the combo box control with three items:
Me.ComboBox1.Items.Add("laptop")
Me.ComboBox1.Items.Add("tablet")
Me.ComboBox1.Items.Add("desktop")
-
4
Add the following code to display the first item:
Me.ComboBox1.Text = Me.ComboBox1.Items(0).ToString()
-
5
Press "F5" to run the program.
-
1
References
- Photo Credit Chad Baker/Ryan McVay/Photodisc/Getty Images