As in Windows forms, you use list boxes to create a control that allows single or multiple selection of items. You can see both a single-selection list box (at left) in Figure 17.3 and a multiple-selection list box (at right) in the ListBoxes example on the CD-ROM.
How do you make multiple selections in a list box? The same way as you would in other Windows controls—you can use the Shift key with the mouse to select a range of items, or the Ctrl key to select multiple items, clicking one after the other.
You use the Rows property to specify the height of the control. To enable multiple item selection, you set the SelectionMode property to ListSelectionMode. Multiple. You can find the selected item in a single-selection list box with the SelectedItem and SelectedIndex properties. The SelectedItem property returns the selected item as a ListItem object, which supports Text, Value, and Selected properties—see "Using the ListItem Class" in Chapter 16. In multiple-selection list boxes, you loop over the Items collection of ListItem objects, checking each item's Selected property to see if that item is selected.
List boxes are supported with the HTML <select> control. Here's the HTML that creates the single-selection list box you see at left in Figure 17.3:
The HTML for the multiple-selection list box at right in Figure 17.3 is almost the same, except for the addition of the multiple attribute (this attribute is a standalone attribute which means you don't have to assign it a value, but following the lead of the XHTML specification, Visual Basic assigns it the value "multiple" to make the HTML more compatible with XML, which does not support standalone attributes):