Skip to main content

ListBox control

A Listbox control allows user to select a single element or an item from a list. And it allows the programmer to add an item(s) at design time or at runtime. This time,open visual basic and create a new application and save it as “listboxcontrol”. Then add a listbox from the toolbox, and it should look like as shown below. Then we can populate the listbox using the window properties. Here’s the following steps 1. Select listbox control 2. Go to the properties window 3. Then select the items 4. And click the ellipses button 5. Then the string Collection Editor dialog box will open 6. And you can enter values one per line. 7. And click OK. And it looks like as shown below: Another way to populate the listbox at design time and add items on it at runtime.to do this, double click the form and add the following code:
  1. ListBox1.Items.Add("Apple")
  2. ListBox1.Items.Add("Banana")
  3. ListBox1.Items.Add("Grapes")
  4. ListBox1.Items.Add("Orange")
  5. ListBox1.Items.Add("Pineapple")
  6. ListBox1.Items.Add("Papaya")
And here’s the output: Example 1:
Example 2:

Add new comment