1 / 6

ListBoxes

Learn about the most common properties and functions used with listbox controls. This guide provides examples and explanations for adding, inserting, removing, selecting, and counting items in a listbox.

markm
Download Presentation

ListBoxes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ListBoxes Monday, March 21, 2011 Roxana Gheorghiu

  2. Short explanation • Next slides list most common properties used with listboxes controls • stringValuemeans that the argument expected or the output for that particular property is a String • indexValuemeans that the argument expected or the output for that particular property is an Integer • The greenlines give an example of how to use that particular property/function • Lst is the variable name of the listbox control

  3. Functions –expect arguments • Lst.Items.Add ( stringValue ) : adds at the end of the list • Lst.Items.Add (“apple”) • Lst.Items.Insert ( indexValue, stringValue ): inserts at a given index • Lst.Items.Insert(0,”orange”) • Lst.Items ( indexValue): returns the item at index indexValue (returns stringValue) • itemVar =Lst.Items(5) • Lst.Items.Remove ( stringValue ): removes an item from the list • Lst.Items.Remove(“apple”) • Lst.Items.RemoveAt ( indexValue): removes the item at a given index • Lst.Items.RemoveAt(2)

  4. Properties –no arguments • Lst.SelectedItem: returns stringValuerepresenting the value of the selected item • Item =Lst.SelectedItem • Lst.SelectedIndex : returns indexValuerepresenting the index of the item selected. Returns -1 if nothing is selected • Index =Lst.SelectedIndex • Lst.Items.Count : returns indexValue representing the number of items in the list (same as length property of Strings) • Size =Lst.items.Count • Lst.Items.Clear: deletes everything in the list

  5. In class exercise Create a program that will have two listboxes: one called lstFruits and the other, called lstColor. Next, the program should do the following: • Display in lstFruits a list of fruits and their color, separated by a “,”. This should be done in the interface design • When you click on any part of the main window (not the button), the program reads one item from the fruit list and adds ONLY the fruit name on that list and the color on the color list • Remove the old values in the lstFruits • Display, in a message box, the fruit selected and its corresponding color. If nothing is selected, display the message: “First select a fruit”

  6. In class exercise (cont.) • Display in a new listbox all the fruits and the colors in reversed order: fruit 1 and last color, fruit 2 and next to last color … • Make a CLEAR button that will remove everything from the new list • Make an In Order checkbox. It it’s checked, the fruits are display with their corresponding color. If it’s not checked, the fruits are displayed as in step 5 • Make an INSERT button that will allow to insert an item below a selected item. If nothing is selected, it will be add at the end • Make a DELETE button that will delete a selected item. If nothing is selected, a Message box will display the message: “First select something

More Related