Home » VB.NET ListBox Control

VB.NET ListBox Control

by Online Tutorials Library

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 Name Description
AllowSelection It takes a value that defines whether the list box allows the user to select the item from the list.
CanSelect It obtains a value that determines whether the Listbox control can be selected.
ColumnWidth It is used to get or set the width of the columns in a multicolumn Listbox.
Container As the name defines, a container gets the IContainer that stores the component of ListBox control.
Controls It is used to get the collection of controls contained within the control.
Created It takes a value that determines whether the control is created or not.
Width It is used to set the width of the ListBox control.
Visible It takes a value that determines whether the ListBox control and all its child are displayed on the Windows Form.
SelectionMode It is used to get or set the method that determines which items are selected in the ListBox.
MultiColumn It allows multiple columns of the item to be displayed by setting the True value in the Listbox.

ListBox Methods

Method Name Description
Add() The Add() method is used to add items to an item collection.
Remove It is used to remove an item from an item collection. However, we can remove items using the item name.
Clear It is used to remove all items from the item collection at the same time.
Contains It 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.
OnNotifyMessage It is used to notify the message of the ListBox to Windows.
GetSelected The 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


You may also like