ComboBox (cbo)

ComboBox - This control allows the user to either select an item from the drop-down list or to enter a different value into the textbox.


ComboBox vs ListBox

The advantage of this control over a listbox is that a value that is not in the list can be entered.
This control is similar to a listbox although a combobox is a drop-down box and it displays only one item at a time.
This is very similar to a list box although a drop down list of possibilities is displaying.


Adding to single column

You can use the "AddItem" method when you have a single column combobox.
If you try to add items to a combobox that has been assigned a RowSource property you will get a "permission denied" error.
You can set the current item using ListIndex.

cboComboBox1.AddItem "one" 
cboComboBox1.AddItem "two"
cboComboBox1.ListIndex = 1 (zero based)

Currently selected item

Obtaining the currently selected item in a combo box.

Call Msgbox (cboComboBox1.Value) 

Select a value

cboComboBox1.Value = "some text" 

Cycle through the whole list

For icount = 0 To cboComboBox1.ListCount - 1 
   If cboComboBox1.List(icount) = "match" Then
   End If
Next icount

Multiple Columns

cboComboBox1.ColumnCount = 2 
cboComboBox1.ColumnWidths = "40;40"
cboComboBox1.AddItem "one"
cboComboBox1.List(0, 1) = "three"

cboComboBox1.AddItem "two", 1
cboComboBox1.List(1, 1) = "four"

Changing the Style

cboComboBox1.Style = fmStyle.fmStyleDropDownCombo 
cboComboBox1.Style = fmStyle.fmStyleDropDownList

To remove scrollbars from appearing set the ColumnWidths to the width of the combobox
In order to have a short combobox or listbox with the dropdown the same width as the text box make the ListWidth property the same value as the width and make the column width the same as the width as well.
The user can also enter a value that does not appear in the list.
To only allow the users to select from the available list change the "Style" property to 2
If you do not want the user to select an entry then change the "MatchEntry" property to -1.
If not then you may get an "Invalid Property Value" error
LinkedCell - 2003
ListFillRange - 2003


Properties

AutoSizeSpecifies whether to automatically resize the control to display its entire contents.
AutoTabSpecifies whether an automatic tab occurs when the maximum number of characters has been entered into the text box.
AutoWordSelectSpecifies how the selection extends or contracts in the text box.
BackColorSpecifies the background color.
BackStyleSets or retrieves the background style (either fmBackStyleTransparent or fmBackStyleOpaque).
BorderColorSpecifies the border color.
BorderStyleSets or retrieves the border style (either fmBorderStyleNone or fmBorderStyleSingle).
BoundColumnIdentifies the source of data in a multicolumn ComboBox.
Column(excluded from Properties window)
ColumnCountSpecifies the number of columns to display in a list box or combo box.
ColumnHeadsDisplays a single row of column headings for list boxes, combo boxes, and objects that accept column headings.
ColumnWidthsSpecifies the width of each column in a multicolumn combo box or list box.
ControlSource(excluded from Properties window)
ControlTipTextSpecifies text that appears when the user briefly holds the mouse pointer over the control without clicking.
CurTargetX(excluded from Properties window)
CurX(excluded from Properties window)
DragBehaviourSpecifies whether the system enables the drag-and-drop feature for a TextBox or ComboBox.
DropButtonStyleSpecifies the symbol displayed on the drop button in a ComboBox.
EnabledSpecifies whether a control can receive the focus and respond to user-generated events.
EnterFieldBehaviourSpecifies the selection behavior when entering a TextBox or ComboBox.
Font 
ForeColorSpecifies the foreground color of an object.
HeightThe height in points.
HideSelectionSpecifies whether selected text remains highlighted when a control does not have the focus.
IMEModeSpecifies the default run time mode of the Input Method Editor (IME) for a control. This property applies only to applications written for East Asia and is ignored in other applications.
LeftThe distance between a control and the left edge of the form that contains it.
LineCount(excluded from Properties window)
List(excluded from Properties window). Allows you to populate a combo box directly from a 1 or 2 dimensional array.
ListCountReturns the number of list entries in a control.
ListIndex(excluded from Properties window)
ListRowsSpecifies the maximum number of rows to display in the list.
ListStyleSpecifies the visual appearance of the list in the combobox (either fmListPlainStyle or fmListStyleOption)
ListWidthSpecifies the width of the list in a ComboBox.
LockedSpecifies whether the control can be edited.
MatchEntryReturns or sets a value indicating how the combobox searches its list as the user types (either fmMatchEntryFirstLetter, fmMatchEntryComplete or fmMatchEntryNone).
MatchFound(excluded from Properties window)
MatchRequiredTrue if the value entered in the text portion of a ComboBox must match an entry in the existing list portion of the control. The user can enter non-matching values, but may not leave the control until a matching value is entered.
MaxLengthSpecifies the maximum number of characters a user can enter in a TextBox or ComboBox.
MouseIconAssigns a custom icon to an object.
MousePointerSpecifies the type of pointer displayed when the user positions the mouse over a particular object.
RowSourceLinks the control to a range of cells on a worksheet.
SelectionMarginSpecifies whether the user can select a line of text by clicking in the region to the left of the text.
SelLength(excluded from Properties window) The number of characters selected in a text box or the text portion of a combo box.
SelStart(excluded from Properties window) Indicates the starting point of selected text, or the insertion point if no text is selected.
SelText(excluded from Properties window) Returns or sets the selected text of a control.
ShowDropButtonWhenSpecifies when to show the drop-down button (either fmShowDropButtonWhenNever, fmShowDropButtonWhenFocus or fmShowDropButtonWhenAlways)
SpecialEffectSpecifies the visual appearance of an object.
StyleSpecifies how the user can choose or set the control's value. The combo box can either behave as a drop-down combo or as a listbox. (either fmStyleDropDownCombo or fmStyleDropDownList)
TabIndexSpecifies the position of a single object in the form's tab order.
TabStopIndicates whether an object can receive focus when the user tabs to it.
Text (default)Control must have focus
TextAlignSpecifies how text is aligned in a control.
TextColumnIdentifies the column in a ComboBox or ListBox to store in the Text property when the user selects a row.
TextLength(excluded from Properties window)
TopIndexSets or retrieves the index of the item displayed in the topmost position in the list.
ValueReturns the text in the textbox portion of the control which was the last selected value.
VisibleSpecifies whether an object is visible or hidden.
WidthThe width in points.

Methods

AddItemFor a single-column list box or combo box, adds an item to the list. For a multicolumn list box or combo box, adds a row to the list.
ClearRemoves all objects from an object or collection.
CopyCopies the contents of an object to the Clipboard.
CutRemoves selected information from an object and transfers it to the Clipboard.
DropDownDisplays the list portion of a ComboBox.
MoveMoves a form or control, or moves all the controls in the Controls collection.
PasteTransfers the contents of the Clipboard to an object.
RemoveItemRemoves a row from the list in a list box or combo box.
SetFocusMoves the focus to this instance of an object.
ZOrderPlaces the object at the front or back of the z-order.

Events

AfterUpdateFires each time the listbox selection changes. This does not fire unless the listbox has its Multi-Select set to Single.
BeforeDragOverOccurs when a drag-and-drop operation is in progress.
BeforeDropOrPasteOccurs when the user is about to drop or paste data onto an object.
BeforeUpdateOccurs before data in a control is changed.
ChangeOccurs when the user changes the selection or clears the items.
ClickThis does not fire unless the list box has its MultiSelect set to Single. In VB.NET this has been replaced with the SelectedIndexChanged and CheckStateChanged events.
DblClickIn VB.NET this has been replaced with the SelectionIndexChanged and TextChanged events.
DropButtonClickOccurs whenever the drop-down list appears or disappears.
EnterOccurs before a control actually receives the focus from a control on the same form.
ErrorOccurs when a control detects an error and cannot return the error information to a calling program.
ExitOccurs immediately before a control loses the focus to another control on the same form.
KeyDownOccurs when the user presses a key.
KeyPressOccurs when the user presses an ANSI key.
KeyUpOccurs when the user releases a key.
MouseDownOccurs when the user presses the mouse button.
MouseMoveOccurs when the user moves the mouse.
MouseUpOccurs when the user releases the mouse button.

© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited TopPrevNext