0% found this document useful (0 votes)
2 views2 pages

Listbox Example

The document provides an example of using a Listbox control in a programming context, demonstrating how to add items and handle selection events. It includes code snippets for the Form_Load and SelectedIndexChanged event to show how to display selected item information. The example illustrates the functionality of selecting multiple items and the corresponding output when an item is selected.

Uploaded by

jilloronaldo20
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Listbox Example

The document provides an example of using a Listbox control in a programming context, demonstrating how to add items and handle selection events. It includes code snippets for the Form_Load and SelectedIndexChanged event to show how to display selected item information. The example illustrates the functionality of selecting multiple items and the corresponding output when an item is selected.

Uploaded by

jilloronaldo20
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LISTBOX EXAMPLE

The Listbox control displays a list of information (such as a shopping list or city list in an address book
program). Each individual item in the list can be checked to indicate that item has been selected.
Multiple items in the list can be selected as well.

The most common event for Listbox control is the SelectedIndexChanged event.

Consider the form design below:

Double click any place on the form (not in the listbox) to open the code window and type
the following code on the “Form_Load” subroutine.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

[Link]("List item 1")


[Link]("List item 2")

End Sub

Next double click on the listbox to open the code window and type the following code:

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles_


[Link]

MsgBox("Selected index = " & [Link])


MsgBox("Selected item = " & [Link])

End Sub

When you run above program and select the first element in the Listbox, the following
output appears.

1
When you click “OK” in the message box above, the following output appears.

You might also like