30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13 Graphical User Interfaces Concepts: Part 2 539<br />

ListBox<br />

properties, methods<br />

and events Description / Delegate and Event Arguments<br />

MultiColumn Indicates whether the ListBox can break a list in<strong>to</strong> multiple columns.<br />

Multiple columns eliminate vertical scrollbars from the display.<br />

SelectedIndex Returns the index of the selected item. If the user selects multiple<br />

items, this property arbitrarily returns one of the selected indices; if no<br />

items have been selected, the property returns -1.<br />

SelectedIndices Returns a collection containing the indices for all selected items.<br />

SelectedItem Returns a reference <strong>to</strong> the selected item (if multiple items are selected,<br />

it returns the item with the lowest index number).<br />

SelectedItems Returns a collection of the selected item(s).<br />

SelectionMode Determines the number of items that can be selected, and the means<br />

through which multiple items can be selected. Values None, One,<br />

MultiSimple (multiple selection allowed) or MultiExtended<br />

(multiple selection allowed using a combination of arrow keys or<br />

mouse clicks and Shift and Control keys).<br />

Sorted Indicates whether items are sorted alphabetically. Setting this property’s<br />

value <strong>to</strong> True sorts the items. The default value is False.<br />

Common Method<br />

GetSelected Takes an index as an argument, and returns True if the corresponding<br />

item is selected.<br />

Common Event (Delegate EventHandler, event arguments EventArgs)<br />

SelectedIndex-<br />

Changed<br />

Generated when selected index changes. This is the default event when<br />

the control is double-clicked in the designer.<br />

Fig. 13.10 ListBox properties, methods and events (part 2 of 2).<br />

The SelectionMode property determines the number of items that can be selected.<br />

This property has the possible values None, One, MultiSimple and MultiExtended<br />

(from the SelectionMode enumeration)—the differences among these settings are<br />

explained in Fig. 13.10. The SelectedIndexChanged event occurs when the user<br />

selects a new item.<br />

Both the ListBox and CheckedListBox have properties Items, SelectedItem<br />

and SelectedIndex. Property Items returns all the list items as a collection.<br />

Collections are a common way of exposing lists of Objects in the .<strong>NET</strong> framework. Many<br />

.<strong>NET</strong> GUI components (e.g., ListBoxes) use collections <strong>to</strong> expose lists of internal objects<br />

(e.g., items contained within a ListBox). We discuss collections further in Chapter 23, Data<br />

Structures and Collections. Property SelectedItem returns the ListBox’s currently<br />

selected item. If the user can select multiple items, use collection SelectedItems <strong>to</strong> return<br />

all the selected items as a collection. Property SelectedIndex returns the index of the<br />

selected item—if there could be more than one, use property SelectedIndices. If no<br />

items are selected, property SelectedIndex returns -1. Method GetSelected takes<br />

an index and returns True if the corresponding item is selected.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!