ListStyle Property

Applies To

ComboBox control, ListBox control.

Description

Specifies the visual appearance of the list in a ListBox or ComboBox.

Syntax

object.ListStyle [= fmListStyle]

The ListStyle property syntax has these parts:

Part

Description

object

Required. A valid object.

fmListStyle

Optional. The visual style of the list.


Settings

The settings for fmListStyle are:

Constant

Value

Description

fmListStylePlain

0

Looks like a regular list box, with the background of items highlighted.

fmListStyleOption

1

Shows option buttons, or check boxes for a multi-select list (default). When the user selects an item from the group, the option button associated with that item is selected and the option buttons for the other items in the group are deselected.


Remarks

The ListStyle property lets you change the visual presentation of a ListBox or ComboBox. By specifying a setting other than fmListStylePlain, you can present the contents of either control as a group of individual items, with each item including a visual cue to indicate whether it is selected.

If the control supports a single selection (the MultiSelect property is set to fmMultiSelectSingle), the user can press one button in the group. If the control supports multiselect, the user can press two or more buttons in the group.

See Also

MultiSelect property.

Example

The following example uses the ListStyle and MultiSelect properties to control the appearance of a ListBox. The user chooses a value for ListStyle using the ToggleButton and chooses an OptionButton for one of the MultiSelect values. The appearance of the ListBox changes accordingly, as well as the selection behavior within the ListBox.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • A ListBox named ListBox1.
  • A Label named Label1.
  • Three OptionButton controls named OptionButton1 through OptionButton3.
  • A ToggleButton named ToggleButton1.
    Private Sub UserForm_Initialize()
        Dim i As Integer
    
        For i = 1 To 8
            ListBox1.AddItem "Choice" & (ListBox1.ListCount + 1)
        Next i
        
        Label1.Caption = "MultiSelect Choices"
        Label1.AutoSize = True
        
        ListBox1.MultiSelect = fmMultiSelectSingle
        OptionButton1.Caption = "Single entry"
        OptionButton1.Value = True
        OptionButton2.Caption = "Multiple entries"
        OptionButton3.Caption = "Extended entries"
        
        ToggleButton1.Caption = "ListStyle - Plain"
        ToggleButton1.Value = True
        ToggleButton1.Width = 90
        ToggleButton1.Height = 30
    End Sub
    
    Private Sub OptionButton1_Click()
        ListBox1.MultiSelect = fmMultiSelectSingle
    End Sub
    
    Private Sub OptionButton2_Click()
        ListBox1.MultiSelect = fmMultiSelectMulti
    End Sub
    
    Private Sub OptionButton3_Click()
        ListBox1.MultiSelect = fmMultiSelectExtended
    End Sub
    
    Private Sub ToggleButton1_Click()
        If ToggleButton1.Value = True Then
            ToggleButton1.Caption = "Plain ListStyle"
            ListBox1.ListStyle = fmListStylePlain
        Else
            ToggleButton1.Caption = "OptionButton or CheckBox"
            ListBox1.ListStyle = fmListStyleOption
        End If
    End Sub