Sams Teach Yourself Visual Basic 6 in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- Introduction
- Who Should Read This Book
- What This Book Will Do for You
- Can This Book Really Teach Visual Basic in 24 Hours?
- What You Need
- Files on the Visual Basic Distribution CD-ROM
- Conventions Used in This Book
- Enough! Time Is Ticking!
- Part I: Introducing Visual Basic
- Hour 1. Visual Basic at Work
- Hour 2.Analyzing Visual Basic Programs
- Hour 3.Controls and Properties
- Hour 4.Examining Labels, Buttons, and Text Boxes
- Part II: Coding the Details
- Hour 5.Putting Code into Visual Basic
- Hour 6.Message and Input Boxes
- Hour 7.Making Decisions
- Hour 8.Visual Basic Looping
- Part III:Putting Code to Work
- Hour 9.Combining Code and Controls
- Hour 10.List Boxes and Data Lists
- Hour 11.Additional Controls
- Hour 12.Dialog Box Basics
- Part IV:Programming with Data
- Hour 13.Modular Programming
- Hour 14.Built-In Functions Save Time
- Hour 15.Visual Basic Database Basics
- Hour 16.Printing with Visual Basic
- Part V:Sprucing Up Programs
- Hour 17.Menus and Visual Basic
- Hour 18.The Graphic Image Controls
- Hour 19.Toolbars and More Graphics
- Hour 20.Writing Correct Applications
- Part VI:Advancing Visual Basic Applications
- Hour 21.Visual Basic and ActiveX
- Hour 22.Object Basics
- Hour 23.Distributing Your Applications
- Hour 24.Online Visual Basic
- Part VII:Appendixes
- Appendix A.Operator Precedence
- Appendix B.Answers
- Appendix C.Using the CD-ROM
Combo Boxes
Combo boxes work much like list boxes except that the user can add items to a combo box at runtime, whereas the user can only scroll and select items from a list box at runtime. Visual Basic supports three kinds of combo boxes, and the kind you select depends on the combo box you want to display on the form and on the ability you want the user to have. All the list box methods that you learned about in the previous section apply to combo boxes.
Here are the three kinds of combo boxes:
- Drop-down combo box—Takes up only a single line on the form unless the user opens the combo box (by pressing the combo box's down arrow) to see additional values. The user can enter additional items at the top of the drop-down combo box and select items from the combo box.
- Simple combo box—Displays items as if they were in a list box. The user can add items to the combo box list (whereas the user cannot with a normal list box).
- Drop-down list box—Doesn't let the user enter new items, so it's similar to a list box. Unlike a list box, however, the drop-down list box normally appears closed to a single line until the user clicks the down arrow button to open the list box to its full size. Technically, drop-down list boxes are not combo box controls but work more like list boxes. The reason drop-down list boxes fall in the combo box control family is that you place drop-down list boxes on forms by clicking the combo box control and setting the Style combo box property.
Figure 10.5 shows the three kinds of combo boxes. Each combo box contains the names of people that you saw in Figure 10.4. The first combo box, the drop-down combo box, is normally closed; when the user clicks its down arrow, the combo box opens. The third combo box, the drop-down list box, is left unopened. If the user opens the drop-down list box, the user will see a list of people's names but will not be able to add to the names because no data entry is possible in drop-down list boxes.
Figure 10.5 Use Style to change the combo box appearance.
Table 10.3 describes some of the combo box properties.
Table 10.3. The fundamental combo box properties.
| Property | Description |
| BackColor | The combo box's background color. |
| ForeColor | The combo box's foreground text color. |
| Height | The height, in twips, of the closed combo box. |
| IntegralHeight | Determines whether the combo box can display partial items, such as the upper half of an item that falls toward the bottom of the combo box. |
| List | A drop-down property list box where you can enter values into the combo box at design time. You can enter only one at a time, and most programmers prefer to initialize the combo box at runtime. |
| Sorted | Determines whether the combo box values are automatically sorted. If False (the default value), the values appear in the same order in which the program added the items to the combo box. |
| Style | Determines the type of combo box your application needs. If 0-DropDown Combo, the combo box is a drop-down combo box. If 1-Simple Combo, the combo box turns into a simple combo box that remains open to the height you used at design time. If 2-DropDown List, the combo box turns into a drop-down list box that remains closed until the user is ready to see more of the list. |
Data Arrays | Next Section

Account Sign In
View your cart