How to Set Visual Basic Combobox Values
- 1). Launch Microsoft Visual Basic Express, click "New Project" on the left pane of the computer screen and double-click "Windows Forms Application" to create a new project.
- 2). Double-click "ComboBox" from the "Toolbox" pane to create a new combo box control. Double-click "Button" to create a new button. Add a ListBox control using the same technique.
- 3). Double-click the form to create a new form load event procedure and type the following code to add five items to the combo box control:
Me.ComboBox1.Items.Add("value 1")
Me.ComboBox1.Items.Add("value 2")
Me.ComboBox1.Items.Add("value 3")
Me.ComboBox1.Items.Add("value 4")
Me.ComboBox1.Items.Add("value 5") - 4). Double-click "Button1" to create a click event for the button and type the following code to add the set of combo box values to a list variable and display the values through a list box:
Dim comboBoxList As New List(Of String)
For Each cmbItem In Me.ComboBox1.Items
comboBoxList.Add(cmbItem)
Next
Me.ListBox1.DataSource = comboBoxList - 5). Press "F5" to run your program and click "Button1" to display the combo box values through the list box.
Source...