The List Box and Combo Box Controls

The List Box control displays data in the form of a list from which the user may select one or more items. The Combo Box control combines the features of a List Box control with a Text Box control, allowing the user to enter a new value if desired. Properties of the List Box and Combo Box controls commonly set at Design Time and Run Time are listed in Table 6.4.

The List Box control may be drawn on the form with varying height and width such that it displays one or more items in the list. If there are more items in the list that can be displayed in the area provided, the scroll bars will automatically appear. Normally the List Box control is drawn with its Height property set to a value large enough for several values to be displayed, because it is difficult to see the scroll bar when the control is at a minimum height. If space on the form is at a premium, use a Combo Box control and set the Style property to dropdown list.

Data is added to the List Box and Combo Box controls at run time using their AddItem() method. ControlName.Additem (item)

Table 6.4 Selected Properties of the List Box and Combo Box Controls r

Property Description

Name Sets the name of the control to use as a code reference to the object.

MultiSelect List Box control only. Indicates whether of not the user will be able to select multiple items in the list.

ColumnCount Sets the number of data columns to be displayed in the list.

ListStyle Indicates whether option buttons (single selection) or check boxes

(multi selection) should appear with items in the list.

Value Holds the current selection in the list. If a multi-select List Box control is used, the BoundColumn property must be used to identify the column from which the Value property is set.

BoundColumn Identifies the column that sets the source of the Value property in a multi-select List Box.

List Run-time only. Used to access the items in the control.

ListCount Run-time only. Returns the number of items listed in the control.

ListIndex Run-time only. Identifies the currently selected item in the control.

Style Combo Box control only. Specifies the behavior of the control as a combo box or a dropdown list box.

The AddItem() method must be called for every row of data added to the list. A looping code structure will often work well to complete this task. Other methods belonging to both the List Box and Combo Box controls include, Clear() and RemoveItem() which remove all or one item from the control's list, respectively. The Combo Box control also includes a DropDown() method that, when invoked, displays the control's list.

The most useful event procedure of the List Box and Combo Box controls is the Change() event. Although you may find the DropButtonClick() event procedure of the Combo Box control quite useful as well. The Change() event is triggered when the Value property of the control changes. (The Value property of the List Box and Combo Box control is the selected item from the list.) The DropButtonClick() event of the Combo Box control is triggered when the controls dropdown button is clicked signaling that the user is viewing the list of items in the control.

Be sure to check the Object Browser for a complete list of properties, methods, and events associated with the ActiveX controls discussed in this chapter.

Biorhythm Awareness

Biorhythm Awareness

Who else wants to take advantage of biorhythm awareness to avoid premature death, escape life threatening diseases, eliminate most of your life altering mistakes and banish catastrophic events from your life.

Get My Free Ebook


Responses

Post a comment