ComboBox Control

Description

Combines the features of a ListBox and a TextBox. The user can enter a new value, as with a TextBox, or the user can select an existing value as with a ListBox.

Remarks

If a ComboBox is bound to a data source, then the ComboBox inserts the value the user enters or selects into that data source. If a multicolumn combo box is bound, then the BoundColumn property determines which value is stored in the bound data source.

The list in a ComboBox consists of rows of data. Each row can have one or more columns, which can appear with or without headings. Some applications do not support column headings, others provide only limited support.

The default property of a ComboBox is the Value property.

The default event of a ComboBox is the Change event.

Note If you want more than a single line of the list to appear at all times, you might want to use a ListBox instead of a ComboBox. If you want to use a ComboBox and limit values to those in the list, you can set the Style property of the ComboBox so the control looks like a drop-down list box.

Properties

AutoSize property, AutoTab property, AutoWordSelect property, BackColor property, BackStyle property, BorderColor property, BorderStyle property, BoundColumn property, BoundValue property, CanPaste property, Column property, ColumnCount property, ColumnHeads property, ColumnWidths property, ControlSource property, ControlTipText property, CurTargetX property, CurX property, DragBehavior property, DropButtonStyle property, Enabled property, EnterFieldBehavior property, Font object, ForeColor property, Height, Width properties, HelpContextID property, HideSelection property, IMEMode property, LayoutEffect property, Left, Top properties, LineCount property, List property, ListCount property, ListIndex property, ListRows property, ListStyle property, ListWidth property, Locked property, MatchEntry property, MatchFound property, MatchRequired property, MaxLength property, MouseIcon property, MousePointer property, Name property, Object property, OldHeight, OldWidth properties, OldLeft, OldTop properties, Parent property, RowSource property, SelectionMargin property, SelLength property, SelStart property, SelText property, ShowDropButtonWhen property, SpecialEffect property, Style property, TabIndex property, TabStop property, Tag property, Text property, TextAlign property, TextColumn property, TextLength property, TopIndex property, Value property, Visible property.

Methods

AddItem method, Clear method, Copy method, Cut method, DropDown method, Move method, Paste method, RemoveItem method, SetFocus method, ZOrder method.

Events

AfterUpdate event, BeforeDragOver event, BeforeDropOrPaste event, BeforeUpdate event, Change event, Click event, DblClick event, DropButtonClick event, Enter, Exit events, Error event, KeyDown, KeyUp events, KeyPress event, MouseDown, MouseUp events, MouseMove event.

See Also

ListBox control, TextBox control.

Example

The following example uses a ComboBox to show the picture placement options for a control. Each time the user clicks a list choice, the picture and caption are updated on the CommandButton. This code sample also uses the AddItem method to populate the ComboBox choices.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • A Label named Label1.
  • A CommandButton named CommandButton1.
  • A ComboBox named ComboBox1.
    Private Sub UserForm_Initialize()
        Label1.Left = 18
        Label1.Top = 12
        Label1.Height = 12
        Label1.Width = 190
        Label1.Caption = "Select picture placement relative to the caption."
        
        'Add list entries to combo box. The value of each entry matches the
        'corresponding ListIndex value in the combo box.
        ComboBox1.AddItem "Left Top"        'ListIndex = 0
        ComboBox1.AddItem "Left Center"     'ListIndex = 1
        ComboBox1.AddItem "Left Bottom"     'ListIndex = 2
        ComboBox1.AddItem "Right Top"       'ListIndex = 3
        ComboBox1.AddItem "Right Center"    'ListIndex = 4
        ComboBox1.AddItem "Right Bottom"    'ListIndex = 5
        
        ComboBox1.AddItem "Above Left"      'ListIndex = 6
        ComboBox1.AddItem "Above Center"    'ListIndex = 7
        ComboBox1.AddItem "Above Right"     'ListIndex = 8
        ComboBox1.AddItem "Below Left"      'ListIndex = 9
        ComboBox1.AddItem "Below Center"    'ListIndex = 10
        ComboBox1.AddItem "Below Right"     'ListIndex = 11
        
        ComboBox1.AddItem "Centered"        'ListIndex = 12
        
        ComboBox1.Style = fmStyleDropDownList   'Use drop-down list
    
        ComboBox1.BoundColumn = 0    'Combo box values are ListIndex values
        ComboBox1.ListIndex = 0             'Set combo box to first entry
    
    
        ComboBox1.Left = 18
        ComboBox1.Top = 36
        ComboBox1.Width = 90
        ComboBox1.ListWidth = 90
        
        'Initialize CommandButton1
        CommandButton1.Left = 230
        CommandButton1.Top = 36
        CommandButton1.Height = 120
        CommandButton1.Width = 120
        
        'Note: Be sure to refer to a bitmap file that is present on your
        'Note: system, and to include the path in the filename.
        CommandButton1.Picture = LoadPicture("c:\windows\argyle.bmp")
        CommandButton1.PicturePosition = ComboBox1.Value
    End Sub
    
    Private Sub ComboBox1_Click()
        Select Case ComboBox1.Value
        Case 0  'Left Top
            CommandButton1.Caption = "Left Top"
            CommandButton1.PicturePosition = fmPicturePositionLeftTop
        
        Case 1  'Left Center
            CommandButton1.Caption = "Left Center"
            CommandButton1.PicturePosition = fmPicturePositionLeftCenter
                
        Case 2  'Left Bottom
            CommandButton1.Caption = "Left Bottom"
            CommandButton1.PicturePosition = fmPicturePositionLeftBottom
            
        Case 3  'Right Top
            CommandButton1.Caption = "Right Top"
            CommandButton1.PicturePosition = fmPicturePositionRightTop
        
        Case 4  'Right Center
            CommandButton1.Caption = "Right Center"
            CommandButton1.PicturePosition = fmPicturePositionRightCenter
        
        Case 5  'Right Bottom
            CommandButton1.Caption = "Right Bottom"
            CommandButton1.PicturePosition = fmPicturePositionRightBottom
        
        Case 6  'Above Left
            CommandButton1.Caption = "Above Left"
            CommandButton1.PicturePosition = fmPicturePositionAboveLeft
        
        Case 7  'Above Center
            CommandButton1.Caption = "Above Center"
            CommandButton1.PicturePosition = fmPicturePositionAboveCenter
            
        Case 8  'Above Right
            CommandButton1.Caption = "Above Right"
            CommandButton1.PicturePosition = fmPicturePositionAboveRight
        
        Case 9  'Below Left
            CommandButton1.Caption = "Below Left"
            CommandButton1.PicturePosition = fmPicturePositionBelowLeft
        
        Case 10 'Below Center
            CommandButton1.Caption = "Below Center"
            CommandButton1.PicturePosition = fmPicturePositionBelowCenter
        
        Case 11 'Below Right
            CommandButton1.Caption = "Below Right"
            CommandButton1.PicturePosition = fmPicturePositionBelowRight
        
        Case 12 'Centered
            CommandButton1.Caption = "Centered"
            CommandButton1.PicturePosition = fmPicturePositionCenter
        
        End Select
        
    End Sub