List Box

The ListBox control, shown in Figure 3-17, allows a selection from a standard group of possible responses. The difference between the ListBox control and the ComboBox control is the ListBox control displays more than a single choice at a time in a list format. Also, you can't type values into a ListBox control.

The following example illustrates how to populate a ListBox control and then respond to the Click event:

Private Sub UserForm_Activate() With ListBox1 .AddItem "Item 1" .AddItem "Item 2" .AddItem "Item 3" End With End Sub

Private Sub ListBox1_Click()

MsgBox "You clicked on: " & ListBox1.List(ListBox1.ListIndex) End Sub

0 0

Post a comment