Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   Display array in list box (https://www.askmehelpdesk.com/showthread.php?t=407240)

  • Oct 18, 2009, 07:28 AM
    vitaming
    Display array in list box
    Hi all,

    How do I display a whole array in one list box? (I want it to be displayed in the form load event... is that possible?)
    For example I want to display these:

    ============================
    mstrMonths(0) = "January"
    mstrMonths(1) = "February"
    mstrMonths(2) = "March"
    mstrMonths(3) = "April"
    ============================
    in a list box.

    I tried doing this:
    ================================================== ======
    lstMonths.Text = mstrMonths(0) & vbNewLine & mstrMonths(1) & vbNewLine & _
    mstrMonths(2) vbNewLine & mstrMonths(3)
    ================================================== ======
    and it didn't work.
  • Oct 19, 2009, 03:10 PM
    Perito
    In VB6, you would do this:

    lstMonths.Clear
    lstMonths.AddItem ("January")
    lstMonths.AddItem ("February")
    ...

    or, if filling from an array
    lstMonths.Clear
    for I = 0 to 11
    lstMonths.AddItem(strMonths(I))
    next I

    In VB.NET, you would do this:

    lstMonths.Items.Clear
    lstMonths.Items.Add("January")
    lstMonths.Items.Add("February")
    ...

    or, if filling from an array
    lstMonths.Items.Clear
    for I as integer = 0 to strMonths.GetUpperBound(0)
    lstMonths.Items.Add(strMonths(I))
    next I

  • All times are GMT -7. The time now is 06:40 AM.