Lecture Four For Windows Programming
Lecture Four For Windows Programming
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.
LISTBOX CONTROL
2
Step 1: Drag the ListBox control from the Toolbox and drop it to the Windows
form, as shown below.
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 3
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.
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 5
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.
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.
GetSelected The GetSelected method is used to validate whether the specified item is
selected.
LISTBOX 7
Let's create a program to select an item from the ListBox in the VB.NET
form.