JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Chapter 7: Windows Forms: List Boxes, Checked List Boxes, Combo Boxes, and Picture Boxes

Main Page

    List Boxes
    Checked List Boxes
    Combo Boxes
    Picture Boxes
    Immediate Solutions: Using the ListBox Class
    Adding Items to a List Box
    Referring to Items in a List Box by Index
    Responding to List Box Events
    Removing Items from a List Box
    Sorting a List Box
    Determining How Many Items Are in a List Box
    Determining Which List Box Items Are Selected
    Making List Boxes Scroll Horizontally (Multicolumn List Boxes)
    Creating Multiselect List Boxes
    Clearing a List Box
    Using the CheckedListBox Class
    Adding Items to Checked List Boxes
    Determining What Items Are Checked in Checked List Boxes
    Checking or Unchecking Items in Checked List Boxes from Code
    Handling Item Check Events in Checked List Boxes
    Using the ComboBox Class
    Creating Simple Combo Boxes, Drop-down Combo Boxes, and Drop-down List Combo Boxes
    Adding Items to a Combo Box
    Responding to Combo Box Selections
    Removing Items from a Combo Box
    Getting the Current Selection in a Combo Box
    Sorting a Combo Box
    Clearing a Combo Box
    Getting the Number of Items in a Combo Box
    Storing Objects in a List Box or Combo Box
    Using the PictureBox Class
    Setting or Getting the Image in a Picture Box
    Adjusting Picture Box Size to Contents
    Handling Picture Box Events (and Creating Image Maps)

In Depth

In this chapter, we're going to take a look at four popular Visual Basic controls: list boxes, checked list boxes, combo boxes, and picture boxes. These controls are part of the core arsenal of every Visual Basic programmer.

List boxes, of course, do just what their name implies: display a list of items. The user can make a selection from that list, and we can handle such selections with event handlers. Because list boxes can use scroll bars if a list gets too long, these controls are very useful to present long lists of items in a way that doesn't take up too much space.

Checked list boxes are derived from list boxes, and also support a checkbox for each item in a list. In VB6 and before, you could add checkboxes to ordinary list boxes, but in VB .NET, checked list boxes are separate controls. These controls are useful when you've got a long list of checkable items and want to scroll that list. We'll see how to handle checkbox events in this control.

Combo boxes are list boxes combined with text boxes. With combo boxes, you can give the user the option of selecting from a list (usually a drop-down list activated when the user clicks the downward pointing arrow at right in a combo box) or typing their selection directly into the text box part of the combo box.

Picture boxes display images, as their name implies. In VB6 and before, picture boxes were powerhouses, not only displaying images, but also letting you edit them as well as reading images from disk and saving them too. And picture boxes were container controls, letting you insert other controls into them. (In fact, in Visual Basic's early days, you used to create toolbars with picture boxes which you filled with buttons.) All that's changed now, unfortunately, and picture boxes have been made much more like VB6's image controls, which only displayed images (image controls do not exist in VB .NET).

I'll take a look at all these controls in some detail here in the In Depth section.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor