JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating Multiple-Selection List Boxes

By default, Web server list boxes let you select only one item at a time, but if you set the SelectionMode property to Multiple, the list box will support multiple selections. You can see the multiple-selection list box in the ListBoxes example on the CD-ROM at work in Figure 17.3.

When the user makes a new selection in a multiple-selection list box, a SelectedIndexChanged event occurs. To determine which items are selected, you can loop over the list box's Items collection, checking each item's Selected property. Here's how I display the selected items in the multiple-selection list box in the ListBoxes example:

   Private Sub ListBox2_SelectedIndexChanged(ByVal sender As _
       System.Object, ByVal e As System.EventArgs) Handles _
       Dim LoopIndex As Integer
       TextBox1.Text = "You selected "
       For LoopIndex = 0 To ListBox2.Items.Count - 1
           If ListBox2.Items(LoopIndex).Selected Then
               TextBox1.Text &= ListBox2.Items(LoopIndex).Text & " "
           End If
   End Sub

And that's all you need.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor