ListWidth Property

Applies To

ComboBox control.

Description

Specifies the width of the list in a ComboBox.

Syntax

object.ListWidth [= Variant]

The ListWidth property syntax has these parts:

Part

Description

object

Required. A valid object.

Variant

Optional. The width of the list. A value of zero makes the list as wide as the ComboBox. The default value is to make the list as wide as the text portion of the control.


Remarks

If you want to display a multicolumn list, enter a value that will make the list box wide enough to fit all the columns.

Tip When designing combo boxes, be sure to leave enough space to display your data and for a vertical scroll bar.

Example

The following example uses a SpinButton to control the width of the drop-down list of a ComboBox. The user changes the value of the SpinButton, then clicks on the drop-down arrow of the ComboBox to display the list.

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

  • A ComboBox named ComboBox1.
  • A SpinButton named SpinButton1.
  • A Label named Label1.
    Private Sub SpinButton1_Change()
        ComboBox1.ListWidth = SpinButton1.Value
        Label1.Caption = "ListWidth = " & SpinButton1.Value
    End Sub
    
    Private Sub UserForm_Initialize()
        Dim i As Integer
    
        For i = 1 To 20
            ComboBox1.AddItem "Choice " & (ComboBox1.ListCount + 1)
        Next i
        
        SpinButton1.Min = 0
        SpinButton1.Max = 130
        SpinButton1.Value = Val(ComboBox1.ListWidth)
        SpinButton1.SmallChange = 5
        Label1.Caption = "ListWidth = " & SpinButton1.Value
    End Sub