Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a listbox from array (Multiple Columns) 1

Status
Not open for further replies.

gal4y

Technical User
Dec 24, 2001
72
US
I would like to take three single dimensional arrays and populate a listbox on a form. Each array should fill one column.

I got this code off line and it doesn't work either.
Code Below.

Not sure what I am doing wrong. I have used the additem, column and rowsource properties.

Dim MyArray() As Double
ReDim MyArray(3, 6)
Dim i As Single

List1.ColumnCount = 3 'The 1st list box contains 3 data columns

'Load integer values into first column of MyArray
For i = 0 To 5
MyArray(i, 0) = i
Next i

'Load columns 2 and 3 of MyArray
MyArray(0, 1) = "Zero"
MyArray(1, 1) = "One"
MyArray(2, 1) = "Two"
MyArray(3, 1) = "Three"
MyArray(4, 1) = "Four"
MyArray(5, 1) = "Five"

MyArray(0, 2) = "Zero"
MyArray(1, 2) = "Un ou Une"
MyArray(2, 2) = "Deux"
MyArray(3, 2) = "Trois"
MyArray(4, 2) = "Quatre"
MyArray(5, 2) = "Cinq"

List1.ListIndex() = MyArray

Thank you for you assistance in advance
Greg

 
Greg, your code looks interesting, I've never seen the manipulation of the listIndex property before. I thought it only RETURNED a value. so I can't comment on that, but...

when populating a multi column listbox, your rowsource is, as usual, a continous, semicolon delimited string.

"Chicago","Boston","St. Louis","New York","Miami","tallahassie","Pheonix","Houston","....

if you have 3 columns, every 4th value, will start a new row.

So, you could try this, after the Array has been populated...

For x = 0 To 5
For y = 0 To 2
strRowSource = strRowSource & ";" & MyArray(x,y)
Next y
Next x

List1.RowSource = Mid(strRowsource,2)

by the way, your array is a two-dimensional array, not single.

Tout de même, bonne chance!
 
Thanks Zion7,

Why List1.RowSource = Mid(strRowsource,2)?

I think I understand teh strrowsouce but the Mid?

Thanks
Greg
 
Greg, because when you first populate the variable strRowsource, the semi colon comes BEFORE the array value.

strRowsource = StrRowSource(empty) & ";" & MyArray(x,y)

so, your variable looks like this ";1;One,Une or Un;2;Two;Deux;3;Three;Trois.....

Will not cause an error, but your first value in the listbox, will be empty. you could go ...

strRowsource = MyArray(x,y) & ";" & StrRowSource

in this case, your last value will be empty, your list box will populate in REVERSE order, and THEN, you would use Stewart's...

List1.RowSource = Left$(strRowsource,Len(strRowSource)-1)

Je suis tres heureux que je t'avais pu aider!
Encore une fois, bonne chance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top