19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

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.

either typing in information or just selecting the appropriate piece of information from a list. The<br />

two most useful types of combo box are denoted as style 0 (Dropdown) <strong>and</strong> style 1 (Simple)<br />

combo boxes. See Figure 10-2. The st<strong>and</strong>ard prefix for the name of a combo box is cbo.<br />

Style 0–Dropdown combo box Style 1–Simple combo box<br />

FIGURE 10-2 Styles of Combo Boxes<br />

With a Simple combo box, the list is always visible. With a Dropdown combo box, the<br />

list drops down when the user clicks on the arrow, <strong>and</strong> then disappears after a selection is<br />

made. In either case, when an item from the list is highlighted, the item automatically appears<br />

in the text box at the top <strong>and</strong> its value is assigned to the Text property of the combo box.<br />

Combo boxes have essentially the same properties, events, <strong>and</strong> methods as list boxes. In<br />

particular, all the statements discussed before for list boxes also hold for combo boxes. The<br />

Style property of a combo box must be specified at design time.<br />

EXAMPLE 3<br />

The following program uses a simple combo box to obtain a person’s title for the first line of the address<br />

of a letter. (Note: At design time, first set the combo box’s Style property to 1, <strong>and</strong> then lengthen the<br />

height of the combo box.)<br />

Object Property Setting<br />

Private Sub cmdDisplay_Click()<br />

txtDisplay.Text = cboTitle.Text & “ ” & txtName.Text<br />

End Sub<br />

List Boxes <strong>and</strong> Combo Boxes 291<br />

frmTitle Caption Letter Address<br />

lblTitle Caption Title<br />

cboTitle List Mr.<br />

Ms.<br />

Dr.<br />

The Honorable<br />

Her Excellency<br />

Style 1 – Simple<br />

Combo<br />

Text (blank)<br />

lblName Caption Name<br />

txtName Text (blank)<br />

cmdDisplay Caption Display Full Name<br />

txtDisplay Text (blank)<br />

[Run, select an item from the combo box, type a name into the Name text box, <strong>and</strong> click the comm<strong>and</strong><br />

button.]

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

Saved successfully!

Ooh no, something went wrong!