Share via


User Input in Combo Boxes

The combo box control has the functionality of a list box and a text box. There are two styles for a combo box: Drop-down combo and Drop-down list. Specify which one you want by changing the Style property of the control. Drop-down lists are discussed in Controls for Displaying Lists.

A user can click the button on a drop-down combo box to see a list of choices or enter a new item directly in the box beside the button. The default Style property of a combo box is 0 — Dropdown Combo.

Adding User Items to Drop-Down Combo Box Lists

To add the new user value to the drop-down combo box, you can use the following line of code in the method associated with the Valid event of the combo box:

THIS.AddItem(THIS.Text)

Before adding an item, however, it would be a good idea to check to make sure that the value is not already in the combo box drop-down:

lItemExists = .F. && assume the value isn't in the list.
FOR i = 1 to THIS.ListCount
   IF THIS.List(i) = THIS.Text
      lItemExists = .T.
      EXIT
   ENDIF
ENDFOR

IF !lItemExists
   THIS.AddItem(THIS.Text)
ENDIF

Common Combo Box Properties

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

Property

Description

ControlSource

Specifies the table field where the value that the user chooses or enters is stored.

DisplayCount

Specifies the maximum number of items displayed in the list.

InputMask

For drop-down combo boxes, specifies the type of values that can be typed in.

IncrementalSearch

Specifies whether the control tries to match an item in the list as the user types each letter.

RowSource

Specifies the source of the items in the combo box.

RowSourceType

Specifies the type of the source for the combo box. The RowSourceType values for a combo box are the same as for a List.

Style

Specifies whether the combo box is a drop-down combo or a drop-down list.

See Also

Reference

Controls for Accepting Input

ComboBox Control

Other Resources

Using Controls