VB.NET ListBox Control

The ListBox control 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 and events window at runtime.

Let's create a ListBox control in the VB.NET Windows by using the following steps.

Step 1: Drag the ListBox control from the Toolbox and drop it to the Windows form, as shown below.

VB.NET ListBox Control

Step 2: Once the ListBox is added to the Form, we can set various properties of the Listbox by clicking on the ListBox control.

ListBox Properties

There are following properties of the ListBox control.

Properties NameDescription
AllowSelectionIt takes a value that defines whether the list box allows the user to select the item from the list.
CanSelectIt obtains a value that determines whether the Listbox control can be selected.
ColumnWidthIt is used to get or set the width of the columns in a multicolumn Listbox.
ContainerAs the name defines, a container gets the IContainer that stores the component of ListBox control.
ControlsIt is used to get the collection of controls contained within the control.
CreatedIt takes a value that determines whether the control is created or not.
WidthIt is used to set the width of the ListBox control.
VisibleIt takes a value that determines whether the ListBox control and all its child are displayed on the Windows Form.
SelectionModeIt is used to get or set the method that determines which items are selected in the ListBox.
MultiColumnIt allows multiple columns of the item to be displayed by setting the True value in the Listbox.

ListBox Methods

Method NameDescription
Add()The Add() method is used to add items to an item collection.
RemoveIt is used to remove an item from an item collection. However, we can remove items using the item name.
ClearIt is used to remove all items from the item collection at the same time.
ContainsIt is used to check whether the particular item exists in the ListBox or not.
Show()It is used to display the control to the user.
Sort()As the name suggests, a Sort() method is used to arrange or sort the elements in the ListBox.
ResetText()A ResetText() method is used to reset ListBox's text property and set the default value.
ResetBackColor()It is used to reset the backColor property of the ListBox and set the default value.
OnNotifyMessageIt is used to notify the message of the ListBox to Windows.
GetSelectedThe GetSelected method is used to validate whether the specified item is selected.

Furthermore, we can also refer to VB.NET Microsoft documentation to get a complete list of ListBox properties, and methods.

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

Listbx.vb

Output:

VB.NET ListBox Control

Now select an item from the list. We have selected Jupiter.

VB.NET ListBox Control

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

VB.NET ListBox Control




Latest Courses