BoundColumn Property

Applies To

ComboBox control, ListBox control.

Description

Identifies the source of data in a multicolumn ComboBox or ListBox.

Syntax

object.BoundColumn [= Variant]

The BoundColumn property syntax has these parts:

Part

Description

object

Required. A valid object.

Variant

Optional. Indicates how the BoundColumn value is selected.


Settings

The settings for Variant are:

Value

Description

0

Assigns the value of the ListIndex property to the control.

1 or greater

Assigns the value from the specified column to the control. Columns are numbered from 1 when using this property (default).


Remarks

When the user chooses a row in a multicolumn ListBox or ComboBox, the BoundColumn property identifies which item from that row to store as the value of the control. For example, if each row contains 8 items and BoundColumn is 3, the system stores the information in the third column of the currently-selected row as the value of the object.

You can display one set of data to users but store different, associated values for the object by using the BoundColumn and the TextColumn properties. TextColumn identifies the column of data displayed in a ComboBox or ListBox; BoundColumn identifies the column of associated data values stored for the control. 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.

If the control is bound to a data source, the value in the column specified by BoundColumn is stored in the data source named in the ControlSource property.

The ListIndex value retrieves the number of the selected row. For example, if you want to know the row of the selected item, set BoundColumn to 0 to assign the number of the selected row as the value of the control. Be sure to retrieve a current value, rather than relying on a previously saved value, if you are referencing a list whose contents might change.

The Column, List, and ListIndex properties all use zero-based numbering. That is, the value of the first item (column or row) is zero; the value of the second item is one, and so on. This means that if BoundColumn is set to 3, you could access the value stored in that column using the expression Column(2).

See Also

ControlSource property, ListIndex property, TextColumn property, Value property.

Example

The following example demonstrates how the BoundColumn property influences the value of a ListBox. The user can choose to set the value of the ListBox to the index value of the specified row, or to a specified column of data in 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, OptionButton2, and OptionButton3.
    Private Sub UserForm_Initialize()
        ListBox1.ColumnCount = 2
    
        ListBox1.AddItem "Item 1, Column 1"
        ListBox1.List(0, 1) = "Item 1, Column 2"
        ListBox1.AddItem "Item 2, Column 1"
        ListBox1.List(1, 1) = "Item 2, Column 2"
        
        ListBox1.Value = "Item 1, Column 1"
        
        OptionButton1.Caption = "List Index"
        OptionButton2.Caption = "Column 1"
        OptionButton3.Caption = "Column 2"
        OptionButton2.Value = True
    End Sub
    
    Private Sub OptionButton1_Click()
        ListBox1.BoundColumn = 0
        Label1.Caption = ListBox1.Value
    End Sub
    
    Private Sub OptionButton2_Click()
        ListBox1.BoundColumn = 1
        Label1.Caption = ListBox1.Value
    End Sub
    
    Private Sub OptionButton3_Click()
        ListBox1.BoundColumn = 2
        Label1.Caption = ListBox1.Value
    End Sub
    
    Private Sub ListBox1_Click()
        Label1.Caption = ListBox1.Value
    End Sub