6
ListBoxes Monday, March 21, 2011 Roxana Gheorghiu

ListBoxes Monday, March 21, 2011 Roxana Gheorghiu

Embed Size (px)

Citation preview

Page 1: ListBoxes Monday, March 21, 2011 Roxana Gheorghiu

ListBoxesMonday, March 21, 2011

Roxana Gheorghiu

Page 2: ListBoxes Monday, March 21, 2011 Roxana Gheorghiu

Short explanationNext 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

Page 3: ListBoxes Monday, March 21, 2011 Roxana Gheorghiu

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)

Page 4: ListBoxes Monday, March 21, 2011 Roxana Gheorghiu

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

Page 5: ListBoxes Monday, March 21, 2011 Roxana Gheorghiu

In class exerciseCreate a program that will have two listboxes: one called lstFruits and the other, called lstColor. Next, the program should do the following:

1. Display in lstFruits a list of fruits and their color, separated by a “,”. This should be done in the interface design

2. 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

3. Remove the old values in the lstFruits

4. Display, in a message box, the fruit selected and its corresponding color. If nothing is selected, display the message: “First select a fruit”

Page 6: ListBoxes Monday, March 21, 2011 Roxana Gheorghiu

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 …

6. Make a CLEAR button that will remove everything from the new list

7. 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

8. 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

9. Make a DELETE button that will delete a selected item. If nothing is selected, a Message box will display the message: “First select something