ImageCombo Control
Provides an enhanced combo box control with icon support, where each item can be associated with an icon from an image list.
Enumerations
ImcStyleConstants
| Constant | Value | Description |
|---|---|---|
| ImcStyleDropDownCombo | 0 | Drop-down combo box (editable) |
| ImcStyleSimpleCombo | 1 | Simple combo box (list always visible) |
| ImcStyleDropDownList | 2 | Drop-down list (selection only) |
ImcEndEditReasonConstants
| Constant | Value | Description |
|---|---|---|
| ImcEndEditReasonLostFocus | 1 | End edit reason: lost focus |
| ImcEndEditReasonReturn | 2 | End edit reason: Enter key pressed |
| ImcEndEditReasonEscape | 3 | End edit reason: Escape key pressed |
| ImcEndEditReasonDropDown | 4 | End edit reason: drop-down selection |
ImcEllipsisFormatConstants
| Constant | Value | Description |
|---|---|---|
| ImcEllipsisFormatNone | 0 | No ellipsis |
| ImcEllipsisFormatEnd | 1 | Ellipsis at the end of text |
ImcComboItem Object
Represents an item in the image combo box.
ImcComboItem Properties
Index
Property Get Index() As LongReturns the index of the item in the collection. Read-only.
Key
Property Get/Let Key() As StringReturns/sets the key of the item.
Tag
Property Get/Let/Set Tag() As VariantReturns/sets the extra data of the item.
Text
Property Get/Let Text() As StringReturns/sets the text of the item.
Image
Property Get/Let Image() As VariantReturns/sets the associated image index or key of the item.
ImageIndex
Property Get ImageIndex() As LongReturns the associated image index of the item. Read-only.
SelImage
Property Get/Let SelImage() As VariantReturns/sets the associated image index or key when the item is selected.
SelImageIndex
Property Get SelImageIndex() As LongReturns the associated image index when the item is selected. Read-only.
Indentation
Property Get/Let Indentation() As LongReturns/sets the indentation level of the item (in icon width units).
Selected
Property Get/Let Selected() As BooleanReturns/sets whether the item is selected.
Data
Property Get/Let Data() As LongPtrReturns/sets the extra numeric data of the item.
ImcComboItems Collection
Represents the collection of all items in the image combo box.
ImcComboItems Properties and Methods
NewEnum
Public Function NewEnum() As IEnumVARIANTReturns an enumerator, supporting For Each syntax.
Add
Public Function Add(Optional ByVal Index As Long, Optional ByVal Key As String, Optional ByVal Text As String, Optional ByVal Image As Variant, Optional ByVal SelImage As Variant, Optional ByVal Indentation As Variant) As ImcComboItemAdds an item to the collection and returns the newly created ImcComboItem object.
Item
Public Property Get Item(ByVal Index As Variant) As ImcComboItemReturns an item by index or key.
Exists
Public Function Exists(ByVal Index As Variant) As BooleanChecks whether an item with the specified index or key exists.
Count
Public Property Get Count() As LongReturns the number of items in the collection.
Clear
Public Sub Clear()Removes all items from the collection.
Remove
Public Sub Remove(ByVal Index As Variant)Removes an item by index or key.
Properties
ControlsEnum
Property Get ControlsEnum() As VBRUN.ParentControlsReturns the parent controls enumerator.
Name
Property Get Name() As StringReturns the name of the control.
Tag
Property Get/Let Tag() As StringReturns/sets the tag value of the control.
Parent
Property Get Parent() As ObjectReturns the parent object of the control.
Container
Property Get/Set Container() As ObjectReturns/sets the container of the control.
Left
Property Get/Let Left() As SingleReturns/sets the position of the left edge of the control.
Top
Property Get/Let Top() As SingleReturns/sets the position of the top edge of the control.
Width
Property Get/Let Width() As SingleReturns/sets the width of the control.
Height
Property Get/Let Height() As SingleReturns/sets the height of the control.
Visible
Property Get/Let Visible() As BooleanReturns/sets whether the control is visible.
ToolTipText
Property Get/Let ToolTipText() As StringReturns/sets the tooltip text of the control.
HelpContextID
Property Get/Let HelpContextID() As LongReturns/sets the help context ID of the control.
WhatsThisHelpID
Property Get/Let WhatsThisHelpID() As LongReturns/sets the "What's This" help ID of the control.
DragIcon
Property Get/Let/Set DragIcon() As IPictureDispReturns/sets the icon displayed during drag operations.
DragMode
Property Get/Let DragMode() As IntegerReturns/sets the drag mode (manual or automatic).
hWnd
Property Get hWnd() As LongPtrReturns the window handle of the image combo box.
hWndUserControl
Property Get hWndUserControl() As LongPtrReturns the window handle of the UserControl.
hWndCombo
Property Get hWndCombo() As LongPtrReturns the window handle of the ComboBoxEx control.
hWndEdit
Property Get hWndEdit() As LongPtrReturns the window handle of the edit box portion.
hWndList
Property Get hWndList() As LongPtrReturns the window handle of the list portion.
Font
Property Get/Let/Set Font() As StdFontReturns/sets the font used by the control.
VisualStyles
Property Get/Let VisualStyles() As BooleanReturns/sets whether visual styles are enabled.
Enabled
Property Get/Let Enabled() As BooleanReturns/sets whether the control is enabled.
OLEDragMode
Property Get/Let OLEDragMode() As VBRUN.OLEDragConstantsReturns/sets the OLE drag mode.
OLEDropMode
Property Get/Let OLEDropMode() As OLEDropModeConstantsReturns/sets the OLE drop mode. See common enumerations.
MousePointer
Property Get/Let MousePointer() As CCMousePointerConstantsReturns/sets the mouse pointer type. See common enumerations.
MouseIcon
Property Get/Let/Set MouseIcon() As IPictureDispReturns/sets the custom mouse icon.
MouseTrack
Property Get/Let MouseTrack() As BooleanReturns/sets whether mouse enter/leave tracking is enabled.
RightToLeft
Property Get/Let RightToLeft() As BooleanReturns/sets whether right-to-left layout is enabled.
RightToLeftLayout
Property Get/Let RightToLeftLayout() As BooleanReturns/sets whether right-to-left layout mirroring is enabled.
RightToLeftMode
Property Get/Let RightToLeftMode() As CCRightToLeftModeConstantsReturns/sets the right-to-left mode. See common enumerations.
ImageList
Property Get/Set/Let ImageList() As VariantReturns/sets the associated ImageList control used to provide item icons.
Style
Property Get/Let Style() As ImcStyleConstantsReturns/sets the combo box style.
Locked
Property Get/Let Locked() As BooleanReturns/sets whether the control is locked (prevents editing and selection).
Text
Property Get/Let Text() As StringReturns/sets the text in the edit box.
Default
Property Get/Let Default() As StringReturns/sets the default value.
Indentation
Property Get/Let Indentation() As LongReturns/sets the default indentation level for new items.
ExtendedUI
Property Get/Let ExtendedUI() As BooleanReturns/sets whether extended user interface is used.
MaxDropDownItems
Property Get/Let MaxDropDownItems() As IntegerReturns/sets the maximum number of visible items in the drop-down list.
ShowImages
Property Get/Let ShowImages() As BooleanReturns/sets whether item icons are displayed.
MaxLength
Property Get/Let MaxLength() As LongReturns/sets the maximum number of characters that can be entered in the edit box.
IMEMode
Property Get/Let IMEMode() As CCIMEModeConstantsReturns/sets the input method editor mode. See common enumerations.
EllipsisFormat
Property Get/Let EllipsisFormat() As ImcEllipsisFormatConstantsReturns/sets the ellipsis format when text exceeds the width.
ScrollTrack
Property Get/Let ScrollTrack() As BooleanReturns/sets whether the scroll bar tracks in real time.
ComboItems
Property Get ComboItems() As ImcComboItemsReturns the combo box items collection. Read-only.
SelStart
Property Get/Let SelStart() As LongReturns/sets the starting position of the selected text.
SelLength
Property Get/Let SelLength() As LongReturns/sets the length of the selected text.
SelText
Property Get/Let SelText() As StringReturns/sets the currently selected text.
TopItem
Property Get/Set TopItem() As ImcComboItemReturns/sets the top visible item in the list.
SelectedItem
Property Get/Set SelectedItem() As ImcComboItemReturns/sets the currently selected item.
DroppedDown
Property Get/Let DroppedDown() As BooleanReturns/sets whether the drop-down list is expanded.
DropDownWidth
Property Get/Let DropDownWidth() As SingleReturns/sets the width of the drop-down list. Not supported in simple style.
OLEDraggedItem
Property Get OLEDraggedItem() As ImcComboItemReturns the item currently being dragged in an OLE drag-drop operation. Read-only.
Methods
OLEDrag
Public Sub OLEDrag()Initiates an OLE drag operation.
Drag
Public Sub Drag(Optional ByRef Action As Variant)Starts, ends, or cancels a drag operation.
SetFocus
Public Sub SetFocus()Moves focus to this control.
ZOrder
Public Sub ZOrder(Optional ByRef Position As Variant)Sets the control's Z-order position within its layer.
Refresh
Public Sub Refresh()Forces a complete redraw of the control.
GetItemHeight
Public Function GetItemHeight() As SingleReturns the height of list items (taking icon height into account).
FindItem
Public Function FindItem(ByVal Text As String, Optional ByVal Index As Long, Optional ByVal Partial As Boolean, Optional ByVal Wrap As Boolean) As ImcComboItemFinds an item in the list and returns a reference to it. When Partial is True, performs partial matching; when Wrap is True, continues searching from the beginning.
Events
Click
Public Event Click()Occurs when the control is clicked.
DblClick
Public Event DblClick()Occurs when the control is double-clicked.
Scroll
Public Event Scroll()Occurs when the list is scrolled.
Change
Public Event Change()Occurs when the control content changes.
DropDown
Public Event DropDown()Occurs when the drop-down list is about to expand.
CloseUp
Public Event CloseUp()Occurs when the drop-down list closes.
ItemDrag
Public Event ItemDrag(ByVal Item As ImcComboItem, ByVal Button As Integer)Occurs when an item initiates a drag-drop operation.
BeginEdit
Public Event BeginEdit()Occurs when the user activates the drop-down list or clicks the edit box.
EndEdit
Public Event EndEdit(ByVal Changed As Boolean, ByVal NewIndex As Long, ByVal NewText As String, ByVal Reason As ImcEndEditReasonConstants)Occurs when an edit operation ends. Changed indicates whether the text changed, NewIndex is the index of the newly selected item, NewText is the new text, and Reason is the end reason.
PreviewKeyDown
Public Event PreviewKeyDown(ByVal KeyCode As Integer, ByRef IsInputKey As Boolean)Occurs before the KeyDown event. Set IsInputKey to mark whether the key is an input key.
PreviewKeyUp
Public Event PreviewKeyUp(ByVal KeyCode As Integer, ByRef IsInputKey As Boolean)Occurs before the KeyUp event.
KeyDown
Public Event KeyDown(KeyCode As Integer, Shift As Integer)Occurs when a keyboard key is pressed.
KeyUp
Public Event KeyUp(KeyCode As Integer, Shift As Integer)Occurs when a keyboard key is released.
KeyPress
Public Event KeyPress(KeyChar As Integer)Occurs when a character key is pressed and released.
MouseDown
Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)Occurs when a mouse button is pressed.
MouseMove
Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)Occurs when the mouse is moved.
MouseUp
Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)Occurs when a mouse button is released.
MouseEnter
Public Event MouseEnter()Occurs when the mouse enters the control.
MouseLeave
Public Event MouseLeave()Occurs when the mouse leaves the control.
OLECompleteDrag
Public Event OLECompleteDrag(Effect As Long)Occurs on the source control after an OLE drag-drop operation is completed or canceled.
OLEDragDrop
Public Event OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)Occurs when data is dropped onto the control via an OLE drag-drop operation.
OLEDragOver
Public Event OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)Occurs when the mouse passes over the control during an OLE drag-drop operation.
OLEGiveFeedback
Public Event OLEGiveFeedback(Effect As Long, DefaultCursors As Boolean)Occurs on the source control when the mouse cursor needs to change during an OLE drag-drop operation.
OLESetData
Public Event OLESetData(Data As DataObject, DataFormat As Integer)Occurs on the source control when the drop target requests data.
OLEStartDrag
Public Event OLEStartDrag(Data As DataObject, AllowedEffects As Long)Occurs when an OLE drag-drop operation is started.
Code Examples
Basic Usage
Private Sub Form_Load()
Set ImageCombo1.ImageList = ImageList1
With ImageCombo1
.Style = ImcStyleDropDownCombo
.ShowImages = True
.MaxDropDownItems = 10
End With
Dim Item As ImcComboItem
Set Item = ImageCombo1.ComboItems.Add(, "k1", "Item One", 1, 2)
Set Item = ImageCombo1.ComboItems.Add(, "k2", "Item Two", 1, 2)
Set Item = ImageCombo1.ComboItems.Add(, "k3", "Sub Item", 3, 4)
Item.Indentation = 1
End Sub
Private Sub ImageCombo1_Click()
If Not ImageCombo1.SelectedItem Is Nothing Then
Debug.Print "Selected: " & ImageCombo1.SelectedItem.Text
End If
End Sub
Private Sub ImageCombo1_EndEdit(ByVal Changed As Boolean, ByVal NewIndex As Long, ByVal NewText As String, ByVal Reason As ImcEndEditReasonConstants)
If Changed Then
Debug.Print "Edit completed: " & NewText
End If
End Sub