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)
ColumnCount 
ColumnHeads 
ColumnWidths 
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)
DragBehaviour 
DropButtonStyle 
Enabled 
EnterFieldBehaviour 
Font 
ForeColor 
Height 
HideSelection 
IMEMode 
Left 
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 
ListIndex(excluded from Properties window)
ListRows 
ListStyleSpecifies the visual appearance of the list in the combobox (either fmListPlainStyle or fmListStyleOption)
ListWidth 
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.
MaxLength 
MouseIcon 
MousePointer 
RowSourceLinks the control to a range of cells on a worksheet.
SelectionMargin 
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)
TabIndex 
TabStop 
Text (default)Control must have focus
TextAlign 
TextColumn 
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.
Visible 
Width 

Methods

AddItem 
Clear 
Copy 
Cut 
DropDown 
Move 
Paste 
RemoveItem 
SetFocus 
ZOrder 

Events

AfterUpdate 
BeforeDragOver 
BeforeDragOrPaste 
BeforeUpdate 
ChangeOccurs when the user changes the selection or clears the items.
Click 
DblClick 
DropButtonClick 
Enter 
Error 
Exit 
KeyDown 
KeyPress 
KeyUp 
MouseDown 
MouseMove 
MouseUp 

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