TextColumn Property

I never noticed this Listbox property before, but it seems like it could be useful. According to help, the TextColumn property sets the column whose value the Text property will return. The BoundColumn property determines what the Value property returns, so this seems to bet the step sister of that.

You can now have easy access to two columns in a multicolumn Listbox. I don't really see a downside since everything in a Listbox is text anyway, so the difference between Value and Text should be nothing. If you don't set the TextColumn property, the Text property returns the same as Value.

This example shows two ways to access a different column than the BoundColumn: One using the List property and one using the Text/TextColumn properties.

Private Sub CommandButton1_Click()
   
    Dim sMsg As String
   
    With Me.ListBox1
        sMsg = "Use TextColumn" & vbNewLine & String(15, "-") & vbNewLine
        sMsg = sMsg & .Value & vbTab & .Text
        sMsg = sMsg & vbNewLine & vbNewLine
        sMsg = sMsg & "No TextColumn" & vbNewLine & String(15, "-") & vbNewLine
        sMsg = sMsg & .Value & vbTab & .List(.ListIndex, 1)
    End With
   
    MsgBox sMsg
   
End Sub

Private Sub UserForm_Initialize()
   
    Dim i As Long
   
    With Me.ListBox1
        .ColumnCount = 2
        .BoundColumn = 1
        .TextColumn = 2
   
        For i = 1 To 10
            .AddItem i
            .List(.ListCount - 1, 1) = i * 10
        Next i
    End With
   
End Sub

userform and message box showing results

2 Comments

  1. Stephen Bullen:

    Hi Dick

    A great use for this is having a two-column list box with and ID in the first column set to zero width. Hence the BoundColumn is 1 and the TextColumn is 2.

    ListBox.Text is what the user sees (e.g. a name)
    ListBox.Value is the corresponding ID.

    Regards

    Stephen Bullen

  2. Dick Kusleika:

    That *is* a great use. I'm sure I'm the last guy to discover this. :)

Leave a comment