Presentation is loading. Please wait.

Presentation is loading. Please wait.

ListBoxes Monday, March 21, 2011 Roxana Gheorghiu.

Similar presentations


Presentation on theme: "ListBoxes Monday, March 21, 2011 Roxana Gheorghiu."— Presentation transcript:

1 ListBoxes Monday, March 21, 2011 Roxana Gheorghiu

2 Short explanation Next slides list most common properties used with listboxes controls stringValue means that the argument expected or the output for that particular property is a String indexValue means that the argument expected or the output for that particular property is an Integer The green lines 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 stringValue representing the value of the selected item Item =Lst.SelectedItem Lst.SelectedIndex : returns indexValue representing 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.) 5. 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


Download ppt "ListBoxes Monday, March 21, 2011 Roxana Gheorghiu."

Similar presentations


Ads by Google