TextColumn Property

Applies To

ComboBox control, ListBox control.

Description

Identifies the column in a ComboBox or ListBox to display to the user.

Syntax

object.TextColumn [= Variant]

The TextColumn property syntax has these parts:

Part

Description

object

Required. A valid object.

Variant

Optional. The column to be displayed.


Settings

Values for the TextColumn property range from –1 to the number of columns in the list. The TextColumn value for the first column is 1, the value of the second column is 2, and so on. Setting TextColumn to 0 displays the ListIndex values. Setting TextColumn to –1 displays the first column that has a ColumnWidths value greater than 0.

Remarks

When the user selects a row from a ComboBox or ListBox, the column referenced by TextColumn is stored in the Text property. For example, you could set up a multicolumn ListBox that contains the names of holidays in one column and dates for the holidays in a second column. To present the holiday names to users, specify the first column as the TextColumn. To store the dates of the holidays, specify the second column as the BoundColumn.

When the Text property of a ComboBox changes (such as when a user types an entry into the control), the new text is compared to the column of data specified by TextColumn.

See Also

BoundColumn property, ColumnWidths property, ListIndex property, Text property.

Example

The following example uses the TextColumn property to identify the column of data in a ListBox that supplies data for its Text property. This example sets the third column of the ListBox as the text column. As you select an entry from the ListBox, the value from the TextColumn will be displayed in the Label.

This example also demonstrates how to load a multicolumn ListBox using the AddItem method and the List property.

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 TextBox named TextBox1.
    Private Sub UserForm_Initialize()
    ListBox1.ColumnCount = 3
    
    ListBox1.AddItem "Row 1, Col 1"
    ListBox1.List(0, 1) = "Row 1, Col 2" 
    ListBox1.List(0, 2) = "Row 1, Col 3"
    
    ListBox1.AddItem "Row 2, Col 1"
    ListBox1.List(1, 1) = "Row 2, Col 2"
    ListBox1.List(1, 2) = "Row 2, Col 3"
    
    ListBox1.AddItem "Row 3, Col 1"
    ListBox1.List(2, 1) = "Row 3, Col 2"
    ListBox1.List(2, 2) = "Row 3, Col 3"
    
    ListBox1.TextColumn = 3
    End Sub
    
    Private Sub ListBox1_Change()
    TextBox1.Text = ListBox1.Text
    End Sub