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
AutoSize | Specifies whether to automatically resize the control to display its entire contents. |
AutoTab | Specifies whether an automatic tab occurs when the maximum number of characters has been entered into the text box. |
AutoWordSelect | Specifies how the selection extends or contracts in the text box. |
BackColor | Specifies the background color. |
BackStyle | Sets or retrieves the background style (either fmBackStyleTransparent or fmBackStyleOpaque). |
BorderColor | Specifies the border color. |
BorderStyle | Sets or retrieves the border style (either fmBorderStyleNone or fmBorderStyleSingle). |
BoundColumn | Identifies the source of data in a multicolumn ComboBox. |
Column | (excluded from Properties window) |
ColumnCount | Specifies the number of columns to display in a list box or combo box. |
ColumnHeads | Displays a single row of column headings for list boxes, combo boxes, and objects that accept column headings. |
ColumnWidths | Specifies the width of each column in a multicolumn combo box or list box. |
ControlSource | (excluded from Properties window) |
ControlTipText | Specifies 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) |
DragBehaviour | Specifies whether the system enables the drag-and-drop feature for a TextBox or ComboBox. |
DropButtonStyle | Specifies the symbol displayed on the drop button in a ComboBox. |
Enabled | Specifies whether a control can receive the focus and respond to user-generated events. |
EnterFieldBehaviour | Specifies the selection behavior when entering a TextBox or ComboBox. |
Font | |
ForeColor | Specifies the foreground color of an object. |
Height | The height in points. |
HideSelection | Specifies whether selected text remains highlighted when a control does not have the focus. |
IMEMode | Specifies 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. |
Left | The 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. |
ListCount | Returns the number of list entries in a control. |
ListIndex | (excluded from Properties window) |
ListRows | Specifies the maximum number of rows to display in the list. |
ListStyle | Specifies the visual appearance of the list in the combobox (either fmListPlainStyle or fmListStyleOption) |
ListWidth | Specifies the width of the list in a ComboBox. |
Locked | Specifies whether the control can be edited. |
MatchEntry | Returns 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) |
MatchRequired | True 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. |
MaxLength | Specifies the maximum number of characters a user can enter in a TextBox or ComboBox. |
MouseIcon | Assigns a custom icon to an object. |
MousePointer | Specifies the type of pointer displayed when the user positions the mouse over a particular object. |
RowSource | Links the control to a range of cells on a worksheet. |
SelectionMargin | Specifies 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. |
ShowDropButtonWhen | Specifies when to show the drop-down button (either fmShowDropButtonWhenNever, fmShowDropButtonWhenFocus or fmShowDropButtonWhenAlways) |
SpecialEffect | Specifies the visual appearance of an object. |
Style | Specifies 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) |
TabIndex | Specifies the position of a single object in the form's tab order. |
TabStop | Indicates whether an object can receive focus when the user tabs to it. |
Text (default) | Control must have focus |
TextAlign | Specifies how text is aligned in a control. |
TextColumn | Identifies the column in a ComboBox or ListBox to store in the Text property when the user selects a row. |
TextLength | (excluded from Properties window) |
TopIndex | Sets or retrieves the index of the item displayed in the topmost position in the list. |
Value | Returns the text in the textbox portion of the control which was the last selected value. |
Visible | Specifies whether an object is visible or hidden. |
Width | The width in points. |
Methods
AddItem | For 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. |
Clear | Removes all objects from an object or collection. |
Copy | Copies the contents of an object to the Clipboard. |
Cut | Removes selected information from an object and transfers it to the Clipboard. |
DropDown | Displays the list portion of a ComboBox. |
Move | Moves a form or control, or moves all the controls in the Controls collection. |
Paste | Transfers the contents of the Clipboard to an object. |
RemoveItem | Removes a row from the list in a list box or combo box. |
SetFocus | Moves the focus to this instance of an object. |
ZOrder | Places the object at the front or back of the z-order. |
Events
AfterUpdate | Fires each time the listbox selection changes. This does not fire unless the listbox has its Multi-Select set to Single. |
BeforeDragOver | Occurs when a drag-and-drop operation is in progress. |
BeforeDropOrPaste | Occurs when the user is about to drop or paste data onto an object. |
BeforeUpdate | Occurs before data in a control is changed. |
Change | Occurs when the user changes the selection or clears the items. |
Click | This 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. |
DblClick | In VB.NET this has been replaced with the SelectionIndexChanged and TextChanged events. |
DropButtonClick | Occurs whenever the drop-down list appears or disappears. |
Enter | Occurs before a control actually receives the focus from a control on the same form. |
Error | Occurs when a control detects an error and cannot return the error information to a calling program. |
Exit | Occurs immediately before a control loses the focus to another control on the same form. |
KeyDown | Occurs when the user presses a key. |
KeyPress | Occurs when the user presses an ANSI key. |
KeyUp | Occurs when the user releases a key. |
MouseDown | Occurs when the user presses the mouse button. |
MouseMove | Occurs when the user moves the mouse. |
MouseUp | Occurs when the user releases the mouse button. |
© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited TopPrevNext