Fill MultiColumn Listbox With Part Of Array

  • I have a multicolumn listbox, and a multidimensional array.
    I want to put just SOME values of the array into the listbox, but I ger errors using both .list or .column to access single items, and even using .additem . Excel Help... does not help at all!


    I have:
    dim variable(2000,2) as string
    variable(1,0)="aaa": variable(1,1)="bbb": variable(1,2)="ccc"
    variable(2,0)="www": variable(2,1)="awasd": variable(1,2)="asdfa"
    ....
    variable(2000,0)="www": variable(2000,1)="awasd": variable(2000,2)="asdfa"


    I don't want to store all 2000 elements, just some ones: how can I do it?!?

  • Re: Filling A Multicolumn Listbox With Part Of Array


    It's hard to understand your question... An example would migth help.. If you have variables defined as you have, and want to add them to an itemlist it should be no problem just:


    Code
    UserForm1.ListBox1.AddItem(variable(2000,0))


    Is the above not working??

  • Re: Filling A Multicolumn Listbox With Part Of Array


    I must admit I'm not too familiar with working with controls etc, but why don't you use an intermediate array that you would populate with the selected values from the master array and then use the intermediate array to populate the Listbox?


    Richard

  • Re: Fill MultiColumn Listbox With Part Of Array


    If using the existing array the following will add an item and populate the other columns.


    [vba]
    UserForm1.ListBox1.AddItem variable(2000,0)
    UserForm1.ListBox1.List(UserForm1.ListBox1.listCount-1,1) = variable(2000,1)
    UserForm1.ListBox1.List(UserForm1.ListBox1.listCount-1,1) = variable(2000,2)
    [/vba]

    [h4]Cheers
    Andy
    [/h4]

  • Re: Fill MultiColumn Listbox With Part Of Array


    Quote from Andy Pope

    If using the existing array the following will add an item and populate the other columns.


    [vba]
    UserForm1.ListBox1.AddItem variable(2000,0)
    UserForm1.ListBox1.List(UserForm1.ListBox1.listCount-1,1) = variable(2000,1)
    UserForm1.ListBox1.List(UserForm1.ListBox1.listCount-1,1) = variable(2000,2)
    [/vba]


    Wasn't even aware you could do that Andy! :)


    Is that a typo in the last line though? Should it be:


    Code
    UserForm1.ListBox1.List(UserForm1.ListBox1.listCount-1,2) = variable(2000,2)


    ?


    Richard

  • Re: Fill MultiColumn Listbox With Part Of Array


    perhaps

    Code
    myStart = 3: myFinish = 6
    For i = myStart To myFinish
    ListBox1.AddItem
    ListBox1.List(ListBox1.ListCount - 1, 0) = variable(i, 1)
    ListBox1.List(ListBox1.ListCount - 1, 1) = variable(i, 2)
    Next i

    p45cal

  • Re: Fill MultiColumn Listbox With Part Of Array


    There's no "List" object in listbox, in VB Express 2005!


    I found this method:

    Code
    For i = 0 To ProgCount2 - 1
                Dim lvi As ListViewItem = MainForm.lstProgrammi.Items.Add(FilteredPrograms(i, 0))
                lvi.SubItems.Add(FilteredPrograms(i, 1))
                lvi.SubItems.Add(FilteredPrograms(i, 2))
                lvi.SubItems.Add(FilteredPrograms(i, 3))
            Next


    off topic: why arent replies notifications sent to me by the forum??? I subscribed this thread!!

  • Re: Fill MultiColumn Listbox With Part Of Array


    jumpjack


    Firstly this is an Excel forum not a VB Express 2005 forum.:)


    So any answers would assume you were using Excel VBA, where there is a List property for listboxes.


    Also you actually appear to be dealing with a listview control not a listbox.


    PS I've got a feeling a listbox in VB Express 2005 does have a list property.


    They certainly did in VB6 and appear to in VB .NET.

    Boo!:yikes:

  • Re: Fill MultiColumn Listbox With Part Of Array


    Quote from norie

    jumpjack


    Firstly this is an Excel forum not a VB Express 2005 forum.:)


    Sorry, it's not yet very clear the difference among VB, VBA, VB.Net...

    Quote

    So any answers would assume you were using Excel VBA, where there is a List property for listboxes.


    Also you actually appear to be dealing with a listview control not a listbox.


    I switched to listview once I saw listbox was not suitable...

  • Re: Fill MultiColumn Listbox With Part Of Array


    Not suitable for what?


    The only thing you asked was how to put particular items from an array in a listbox.


    You gave no details of the actual array or the criteria for whether or not an item goes in the listbox or where the items should go exactly.:)

    Boo!:yikes:

  • Re: Fill MultiColumn Listbox With Part Of Array


    Why did you decide the listbox wasnt suitable?


    Quote from jumpjack

    off topic: why arent replies notifications sent to me by the forum??? I subscribed this thread!!


    There is a setting under options in your control panel to change the default susbcription when subscribing to a thread.


    Please check that.
    Please also check you have given the correct email address.

  • Re: Fill MultiColumn Listbox With Part Of Array


    Along with the above, check your spam filter and/or junk email folder.


    BTW, why haven't you at least said "thanks" to those that are helping??

  • Re: Fill MultiColumn Listbox With Part Of Array


    Quote from norie

    Not suitable for what?


    The only thing you asked was how to put particular items from an array in a listbox.


    You gave no details of the actual array or the criteria for whether or not an item goes in the listbox or where the items should go exactly.:)


    I was just trying to get a 100x4 array displayed on the screen. It's quite hard to access single elements of a listview (in VB.NET) just by using Add and Remove methods; I eventually found that I must use something like this:
    mylistview.items(i).subitems.items(j) to access element (i,j) of the listview array!! :roll:
    Very tricky... In VBA I just had to use listview.list(i,j) !![hr]*[/hr] Auto Merged Post;[dl]*[/dl]


    I already checked the option for automatic subscription! Indeed, the checkbox at the end of post/reply form is checked. But I didn't receive notifications for first replies, although I received them for these new ones.... :roll:


    Don't know, maybe I discarded some emails...

  • Re: Fill MultiColumn Listbox With Part Of Array


    Quote from norie

    I don't see why you couldn't display a 100 by 4 array in a listbox.:confused:


    I don't know, I just gave up after first troubles.... Maybe it's possible to access single elements in a listbox, too.. (in VB.NET)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!