Share via


Application of List Boxes and Drop-Down List Boxes

List boxes and drop-down list boxes (combo box controls with the Style property set to 2 - Dropdown List) provide a user with scrollable lists that contain a number of options or pieces of information. In a list box, multiple items can be visible at all times. In a drop-down list box, only one item is visible, but a user can click the down button to display a scrolling list of all the items in the drop-down list box.

Run Solution.app in the Visual FoxPro \Samples\Solution directory to see several examples that demonstrate using list boxes and drop-down list boxes, including the following:

  • Add pictures to a list.

  • Multiselect items in a list.

  • Fill a list with values from different sources.

  • Display multiple columns in a list.

  • Sort list items.

  • Move items between lists.

    Tip   If you have room on the form and if you want to emphasize the choices a user has, use a list. To conserve space and emphasize the currently selected item, use a drop-down list box.

Common List Properties and Methods

The following list box properties are commonly set at design time.

Property Description
ColumnCount The number of columns in the list box.
ControlSource Where the value that a user chooses from the list is stored.
MoverBars Whether mover bars are displayed to the left of list items so that a user can easily rearrange the order of items in the list.
Multiselect Whether the user can select more than one item in the list at a time.
RowSource Where the values displayed in the list come from.
RowSourceType Whether the RowSource is a value, a table, a SQL statement, a query, an array, a list of files, or a list of fields.

Note   The Value property of a list can be numeric or character. The default is numeric. Set the Value property to an empty string if the RowSource is a character value and if you want the Value property to reflect the character string of the selected item in the list. You can press the SPACEBAR and then the BACKSPACE key to enter an empty string for a property in the Properties window.

The following list box methods are commonly used.

Method Description
AddItem Adds an item to a list with a RowSourceType of 0.
RemoveItem Removes an item from a list with a RowSourceType of 0.
Requery Updates the list if the values in the RowSource have changed.

Filling a List Box or a Combo Box

You can fill a list box with items from a variety of sources by setting the RowSourceType and RowSource properties.

See Also

Storing User Choices to a Table Using Option Buttons | Choosing the Type of Data for a List or Combo Box | Creating Multicolumn List Boxes | Using Controls | Controls and Objects