Chapter 6 Using Decision Structures 175
When you’ve finished setting properties, your form looks similar to this:
Now you’ll enter the program code to initialize the list box.
- Double-click the form.
The Form1_Load event procedure appears in the Code Editor.
- Type the following program code to initialize the list box:
lstCountryBox.Items.Add("England")
lstCountryBox.Items.Add("Germany")
lstCountryBox.Items.Add("Mexico")
lstCountryBox.Items.Add("Italy")
These lines use the Add method of the list box object to add entries to the list box on
your form.
- Click the Form1 .vb [Design] tab at the top of the Code Editor to switch back to the
Designer, and then double-click the list box object on your form to edit its event
procedure.
The lstCountryBox_SelectedIndexChanged event procedure appears in the Code Editor. - Type the following lines to process the list box selection made by the user:
lblCountry.Text = lstCountryBox.Text
Select Case lstCountryBox.SelectedIndex
Case 0
lblGreeting.Text = "Hello, programmer"
Case 1
lblGreeting.Text = "Hallo, programmierer"
Case 2
lblGreeting.Text = "Hola, programador"
Case 3
lblGreeting.Text = "Ciao, programmatore"
End Select