ListBox Control (VBCCRListBox)
The VBCCRListBox control is a list box control used to display multiple options for user selection. It supports single and multiple selection modes and can display plain text or icon list items.
Properties
Appearance Properties
Style
- List box style(0-2)vbListBoxStandard
(0) - Standard list boxvbListBoxCheckbox
(1) - List box with checkboxesvbListBoxOption
(2) - List box with option buttons
BackColor
- Background colorForeColor
- Foreground colorFont
- Font propertiesBorderStyle
- Border styleAppearance
- AppearanceEnabled
- Whether enabledVisible
- Whether visible
List Properties
List
- Array of list itemsListCount
- Number of list itemsListIndex
- Index of currently selected itemMultiSelect
- Whether to allow multiple selectionvbMultiSelectNone
(0) - Single selectionvbMultiSelectSimple
(1) - Simple multiple selectionvbMultiSelectExtended
(2) - Extended multiple selection
Selected(Index)
- Whether specified item is selectedSelCount
- Number of selected itemsTopIndex
- Index of first visible itemItemData
- Numeric data associated with list itemsSorted
- Whether automatically sortedIntegralHeight
- Whether to use integer row heightItemHeight
- Item height
Events
Click
- Triggered when clickedDblClick
- Triggered when double-clickedItemCheck
- Triggered when item check state changes (checkbox style only)MouseDown
- Triggered when mouse button is pressedMouseMove
- Triggered when mouse movesMouseUp
- Triggered when mouse button is releasedScroll
- Triggered when scrolledKeyDown
- Triggered when key is pressed downKeyPress
- Triggered during key pressKeyUp
- Triggered when key is released
Methods
AddItem
- Add list itemRemoveItem
- Remove list itemClear
- Clear listRefresh
- Refresh displaySetFocus
- Set focus
Code Examples
Basic Usage
vb
Private Sub InitListBox()
With ListBox1
.Clear ' Clear list
' Add items
.AddItem "Item 1"
.AddItem "Item 2"
.AddItem "Item 3"
.ListIndex = 0 ' Select first item
End With
End Sub
Multiple Selection List Box
vb
Private Sub InitMultiSelectList()
With ListBox1
.MultiSelect = vbMultiSelectExtended
.Clear
' Add items
Dim i As Long
For i = 1 To 10
.AddItem "Option " & i
Next i
End With
End Sub
Private Function GetSelectedItems() As String()
Dim Count As Long
Count = ListBox1.SelCount
If Count = 0 Then
GetSelectedItems = Array()
Exit Function
End If