Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Populate a List Box from an array (Word XP)

    I don't know what I'm doing wrong so I hope someone can help.

    Below is what I added at the declaration section of the form:
    Dim x1(2, 3) As Variant


    Below is at the Private Sub UserForm_Initialize()
    x1(1, 1) = "Bold"
    x1(1, 2) = "B1"
    x1(1, 3) = "B2"
    x2(2, 1) = "Italic"
    x2(2, 2) = "I1"
    x2(2, 3) = "I2"

    I am assuming I created the arrays correctly. But I can seem to find out how to load all the rows, but only the first column in the list box. So from the example above, the list box will only show Bold and Italic.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Populate a List Box from an array (Word XP)

    Are you using ListBox1.List = x1 ?

    Make sure the ColumnCount property of ListBox1 is set to 3. Also, you might avoid potential problems by using 0 based indexing in your array, as the ListBox does by default. Or maybe Option Base 1 fixes both??

    One more thing: in your example, x2 should be x1.

  3. #3
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate a List Box from an array (Word XP)

    I modified it so they look like this now:
    x(0, 1) = "Bold"
    x(0, 2) = "B1"
    x(0, 3) = "B2"
    x(1, 1) = "Italic"
    x(1, 2) = "I1"
    x(1, 3) = "I2"


    Now regarding the list box, I don't want 3 columns, so I ColumnCountProperty is set to 1 What I couldn't figure out was how to load the values of x(1, 1) and x(2, 1) in the list box. So that when the list box is shown, only 2 items are listed, Bold and Italics.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Populate a List Box from an array (Word XP)

    Works for me, one column listbox named ListBox1 and this routine:

    Private Sub UserForm_Initialize()
    Dim x(0 To 1, 1 To 3) As Variant
    x(0, 1) = "Bold"
    x(0, 2) = "B1"
    x(0, 3) = "B2"
    x(1, 1) = "Italic"
    x(1, 2) = "I1"
    x(1, 3) = "I2"
    Me.ListBox1.List = x
    End Sub

    The listbox shows Bold on the first row, Italic on the second row. What am I missing?

  5. #5
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate a List Box from an array (Word XP)

    Great, i thought I needed a loop to only add the first column.

    Thanks so much! You guys been pretty patient with me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •