ListBox Control in VB.net – Properties, Methods and Events

What is ListBox Control in VB.net?

A ListBox Control in VB.net is used to display a list of items in Windows form.

It allows the user to select one or more items from the ListBox Control.

Furthermore, we can add or design the list box by using the properties, methods, and events window at runtime.

Let’s create a list box by dragging a ListBox Control from the Toolbox and dropping it on the form.

ListBox Control in VB.net Tutorial
ListBox Control in VB.net Tutorial

You can populate the list box items either from the properties window or at runtime.

To add items to a ListBox, select the ListBox control and get to the properties window, for the properties of this control.

Click the ellipses (…) button next to the Items property.

This opens the String Collection Editor dialog box, where you can enter the values one at a line.

Properties of the ListBox Control in VB.net

The following are some commonly used Properties of the ListBox Control in VB.net.

#Properties of the ListBox Control in VB.netDescription
1.AllowSelectionGets or sets the width of columns in a multicolumn list box.
2.BorderStyleGets or sets the type of border drawn around the list box.
3.ColumnWidthGets of sets the width of columns in a multicolumn list box.
4.HorizontalExtentGets or sets the horizontal scrolling area of a list box.
5.HorizontalScrollBarGets or sets the value indicating whether a horizontal scrollbar is displayed in the list box.
6.ItemHeightGets or sets the height of an item in the list box.
7.ItemsGets the items of the list box.
8.MultiColumnGets or sets a value indicating whether the list box supports multiple columns.
9.ScrollAlwaysVisibleGets or sets a value indicating whether the vertical scroll bar is shown at all times.
10.SelectedIndexGets or sets the zero-based index of the currently selected item in a list box.
11.SelectedIndicesGets a collection that contains the zero-based indexes of all currently selected items in the list box.
12.SelectedItemGets or sets the currently selected item in the list box.
13.SelectedItemsGets a collection containing the currently selected items in the list box.
14.SelectedValueGets or sets the value of the member property specified by the ValueMember property.
15.SelectionModeGets or sets the method in which items are selected in the list box. This property has values −NoneOneMultiSimpleMultiExtended
16.SortedGets or sets a value indicating whether the items in the list box are sorted alphabetically.
17.TextGets or searches for the text of the currently selected item in the list box.
18.TopIndexGets or sets the index of the first visible item of a list box.
Properties and Description of the ListBox Control in VB.net

Methods of the ListBox Control in VB.net

The following are some commonly used Methods of ListBox Control in VB.net.

#Methods of the ListBox Control in VB.netDescription
1.BeginUpdatePrevents the control from drawing until the EndUpdate method is called, while items are added to the ListBox one at a time.
2.ClearSelectedUnselects all items in the ListBox.
3.EndUpdateFind the first item in the ListBox that starts with the string specified as an argument.
4.FindStringFinds the first item in the ListBox that starts with the string specified as an argument.
5.FindStringExactFind the first item in the ListBox that exactly matches the specified string.
6.GetSelectedReturns a value indicating whether the specified item is selected.
7.SetSelectedSelects or clears the selection for the specified item in a ListBox.
8.OnSelectedIndexChangedRaises the SelectedIndexChanged event.
9.OnSelectedValueChangedRaises the SelectedValueChanged event.
Methods and Descriptions of the ListBox Control in VB.net

Events of the ListBox Control in VB.net

The following are some of the commonly used Events of the ListBox Control in VB.net.

#Events of the ListBox Control in VB.netDescription
1.ClickOccurs when a list box is selected.
2.SelectedIndexChangedOccurs when the SelectedIndex property of a list box is changed.
Events and Descriptions of the ListBox Control in VB.net

Let’s create a program to select an item from the ListBox in the VB.NET form.

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub Button1_Click_1(sender As Object, e As EventArgs)

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ListBox1.Items.Add("Red horse")
        ListBox1.Items.Add("Emperador")
        ListBox1.Items.Add("Fundador")
        ListBox1.Items.Add("Alfonso")
        ListBox1.Items.Add("San Mig")
        ListBox1.Items.Add("Tanduay")
    End Sub

    Private Sub Button1_Click_2(sender As Object, e As EventArgs)

    End Sub

    Private Sub Button1_Click_3(sender As Object, e As EventArgs) Handles Button1.Click
        Dim lt As String  ' define a local variable.  
        lt = ListBox1.Text  'accept the data from the ListBox1  
        MsgBox(" Selected Drinks is: " & lt)  ' Display the selected item
    End Sub
End Class

Program Output:

ListBox Control in VB.net Output
ListBox Control in VB.net Output

Now select an item from the list. We have selected Red Horse.

ListBox Control in VB.net Selecting Item
ListBox Control in VB.net Selecting Item

Click on the Show button to display the selected item in Windows Form, as follows.

ListBox Control in VB.net Display Message Box
ListBox Control Display Message Box

Summary

In this article, we discussed How To Create a VB.net ListBox Control in Windows Forms using Microsoft Visual Studio at design-time and run-time.

After that, we saw how to use various properties, events, and methods.


Common use cases for ListBox Control

ListBox Control is a standard Windows Forms element that appears in most VB.NET desktop apps. Typical uses:

  • User input capture. Bind to viewmodel properties for two-way data flow.
  • Display of collections. Populate with in-memory lists, database result sets, or file system contents.
  • Event-driven behaviors. Wire up Click, SelectedIndexChanged, or KeyDown handlers for interactivity.
  • Data validation. Use Validating and Validated events to enforce input rules before persistence.
  • Custom styling. Override OnPaint or use owner-draw modes for branded looks.

Wiring ListBox Control into your form

The standard pattern for adding ListBox Control at runtime looks like this:

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Configure the control's initial state
        Me.Text = "ListBox Control Example"
        ' Attach event handlers programmatically
        AddHandler MyControl.Click, AddressOf MyControl_Click
    End Sub

    Private Sub MyControl_Click(sender As Object, e As EventArgs)
        ' React to user interaction here
        MessageBox.Show("Control was clicked")
    End Sub

End Class

Best practices for ListBox Control

  • Name controls consistently. Use a Hungarian-style prefix (btn, txt, lbl, lst) so the codebehind reads cleanly.
  • Group related controls in a Panel or GroupBox. Improves layout maintainability and keyboard tab order.
  • Set TabIndex explicitly. Do not rely on design-time order; keyboard navigation matters for accessibility.
  • Use data binding when possible. Avoid manual .Text = someValue assignments scattered across the codebehind.
  • Handle Dispose(). Custom controls that hold GDI resources must implement IDisposable properly.

Troubleshooting ListBox Control

  • Event handler does not fire. Confirm the Handles clause matches the exact control name, or that AddHandler was called.
  • Design-time appearance differs from runtime. This usually means custom OnPaint code is not respecting DesignMode. Check with Me.DesignMode.
  • Control flashes or flickers on redraw. Enable double-buffering by setting DoubleBuffered = True on the parent form.
  • Cross-thread exceptions. UI updates from background threads must use Control.Invoke() or the BackgroundWorker.ReportProgress pattern.

Frequently Asked Questions

What is the ListBox Control in VB.NET used for?
The ListBox Control is a Windows Forms control that captures user input or displays data in a familiar UI element. It sits in the Toolbox in Visual Studio and can also be created at runtime through code.
How do I add the ListBox Control to my form?
Drag it from the Visual Studio Toolbox onto the form designer, or instantiate it in code with New and add it to Me.Controls. Both approaches produce identical runtime behavior.
What are the most-used ListBox Control properties?
Name, Text, Location, Size, and Enabled are set on almost every instance. Font, ForeColor, and BackColor are common for styling. Anchor and Dock control how the control resizes with the form.
How do I handle ListBox Control events?
Double-click the control in the form designer to auto-generate a default event handler. Or wire up manually with AddHandler MyControl.EventName, AddressOf HandlerMethod inside Form_Load.
Can I use the ListBox Control in WPF or MAUI?
No. Windows Forms controls are specific to WinForms. WPF has its own control hierarchy under System.Windows.Controls, and MAUI uses cross-platform equivalents. Use the framework-appropriate control instead.
Angel Jude Suarez


Full-Stack Developer at PIES IT Solution

Focuses on Python development, machine learning, and AI integration. Has built production AI systems including OpenAI Whisper integration for medical transcription and GPT-4o-powered diagnosis assistance. Strong background in pandas, scikit-learn, and TensorFlow.

Expertise: Python · PHP · Java · VB.NET · ASP.NET · Machine Learning · AI Integration · OpenCV · Django · CodeIgniter
 · View all posts by Angel Jude Suarez →

Leave a Comment