ListBox control

Submitted by: 

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 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

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.