PDA

View Full Version : Display array in list box


vitaming
Oct 18, 2009, 07:28 AM
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.

Perito
Oct 19, 2009, 03:10 PM
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