Programmers often display a list of items through a "ListBox" control from which the user can choose. Depending on your application, you may want to give the user the flexibility to remove items they don't use. In Visual Basic, you can use the "Items" property to obtain a reference to the list of items currently stored in the ListBox control. With that reference, you can add or remove items. Use the "Selected Item" to access the current selection and clear it.
- Skill level:
- Moderately Easy
Other People Are Reading
Things you need
- Microsoft Visual Basic Express
Launch Microsoft Visual Basic Express, click "New Project" on the left pane of your computer screen, and double-click "Windows Forms Application" to create a new project.
Double-click "ListBox" from the "Toolbox" pane to add a new ListBox to the form. Double-click "Button" to create a new button on your form.
Double-click the form to create a new "Load" event procedure, and add the following code to add five new items to the ListBox:
Me.ListBox1.Items.Add("second item") Me.ListBox1.Items.Add("third item") Me.ListBox1.Items.Add("fourth item") Me.ListBox1.Items.Add("fifth item")
Double-click the button to create a new click event procedure, and add the following code to access and clear the current item selected:
Press "F5" to run the program and click any item on the ListBox control. Click "Button1" to clear the item.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for