11 columns in listbox - AutoCAD-VBA

11 columns in listbox - AutoCAD-VBA

Ray-Sync
Advocate Advocate
995 Views
5 Replies
Message 1 of 6

11 columns in listbox - AutoCAD-VBA

Ray-Sync
Advocate
Advocate

Hi everyone. I want to have 11 columns in my listbox. Can you help me?

jefer_ing_1-1674618608758.pngjefer_ing_2-1674618627785.png

 

jefferson
0 Likes
Accepted solutions (1)
996 Views
5 Replies
Replies (5)
Message 2 of 6

Ed__Jobe
Mentor
Mentor

You already have 11 columns when you set the ColumnCount property. The List property is used to set the contents of the List. In your sample, you are trying to set the list address of Row 0, Column 10 to an integer of 11. Note what help says:


VBA Help wrote:

Remarks

The List property works with the ListCount and ListIndex properties.Use List to access list items. A list is a variant array; each item in the list has a row number and a column number.

 


 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 6

Ray-Sync
Advocate
Advocate

Hello @Ed__Jobe.
Thanks for your answer. Maybe you have given me the solution but I do not catch it. Columncount works from 1 to 10 but it does not work from 11 or more. I need 15 columns in my Listbox. Can you give me a vba code to have 15 columns in my listbox?

jefferson
0 Likes
Message 4 of 6

Ed__Jobe
Mentor
Mentor
Accepted solution

You can have 15 columns. See below. Remember that the column numbers are zero indexed. 0-14 = 15 columns. The ColumnCount property sets the number of columns, the List property sets the contents of the cell.

listbox 15.png

Here's an example of setting the List property.

 

Public Sub FillFileList()

    'fill ListFiles list box with file names in StrDir global var
    Dim strFileList() As String
    Dim strFileName As String
    Dim i As Integer
    
    i = 0
    ReDim strFileList(i)
    strFileName = Dir(strDir + "*.scr")
    While Not strFileName = ""
        ReDim Preserve strFileList(i)
        'store filename in array
        strFileList(i) = strFileName
        i = i + 1
        'get next filename
        strFileName = Dir()
    Wend
    ListFiles.List = strFileList
End Sub

So, your problem is with:

.List(0,10) = 11

You need to create an array with values to be assigned to the List method.

Private Sub UserForm_Initialize()
    Dim strList(2, 2) As String
    strList(0, 0) = "Col 1"
    strList(0, 1) = "Col 2"
    strList(0, 2) = "Col 3"
    strList(1, 0) = "R1C1"
    strList(1, 1) = "R1C2"
    strList(1, 2) = "R1C3"
    With ListBox1
        .ColumnCount = 3
        .ColumnWidths = "0.5 in;0.5 in;0.5 in"
        .List = strList
    End With
End Sub

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 6

Ray-Sync
Advocate
Advocate

I'm going to try it.

jefferson
0 Likes
Message 6 of 6

Ray-Sync
Advocate
Advocate
It works. Thank you.
jefferson
0 Likes