ComboBox Control

Creates a combo box, which initially displays a single item. However, when you select the combo box, it displays a list of items that you can choose an item from. A combo box combines the features of a text box and a list box. You can enter information in the text box portion or select an item from the list box portion of the control.

Tip

The Style property determines the type of list that the ComboBox control contains. To create a drop-down combo box, which displays a drop-down list and edit box, set the Style property to 0. To create a drop-list box, which displays a drop-down list only, set the Style property to 2.

To show or hide the list in a combo box, select the control and press ALT+DOWN ARROW.

For information about creating ComboBox controls, see Form Designer and Using Controls.

ComboBox

Remarks

The following table lists properties commonly set at design time.

Property Description

ColumnCount Property (Visual FoxPro)

Determines the number of columns in the list.

ControlSource Property

Specifies where to store the value that the user chooses from the list.

MoverBars Property

Specifies whether to display mover bars to the left of the items in the list so that a user can rearrange the item order.

MultiSelect Property (Visual FoxPro)

Specifies whether the user can select more than one item in the list.

RowSource Property

Specifies the source of the values displayed in the list.

RowSourceType Property

Specifies the type of the source of the values displayed in the list.

The following table lists methods commonly used.

Method Description

AddItem Method (Visual FoxPro)

Adds an item to the list when RowSourceType is set to 0.

RemoveItem Method

Removes an item from the list when RowSourceType is set to 0.

Requery Method

Updates the list if the values in the source specified by RowSource have changed.

The backslash ("\") is treated as a special character when used in the expression for an item. The following rules apply for this character

  • You can disable an item in a list box or combo box by adding a single backslash to the beginning of the expression.

  • Any multiple of two backslashes used in the expression is displayed as a single backslash. For example, one or two backslashes used together display as one, and three or four backslashes together display as two. The following example code contains a list box item containing a Universal Naming Convention (UNC) path. The code displays in the list box as \\MyServer\MyMachine\MyFolder.

    MyForm.List1.AddItem("\\\\MyServer\\MyMachine\\MyFolder")
    
  • If the expression begins with multiple backslashes, the item is not disabled. If you want to disable an item that begins with multiple backslashes, add a backslash and a close bracket (]) to the beginning of the item. For example, the following would disable the UNC path item in the list box.

    MyForm.List1.AddItem("\]\\\MyServer\\MyMachine\\MyFolder")
    
  • To include a separator line use a backslash followed by a hyphen as the item to add to the list box. For example, the following code adds a separator line to a list box.

    MyForm.List1.AddItem("\-")
    

You can also use an ActiveX control that adds extra characteristics, such as a Checkbox control, to the ListView or TreeView controls.

See Also

Reference

ComboBox Control Properties, Methods, and Events
CREATE CLASS Command
CREATE FORM Command
DEFINE CLASS Command

Other Resources

Objects, Collections, and Classes
Language Reference (Visual FoxPro)