Link to home
Start Free TrialLog in
Avatar of whitej8
whitej8

asked on

Adding Items to Multi column listbox

I am using a multicolumn listbox, how do I add items to each column?
ASKER CERTIFIED SOLUTION
Avatar of BergJC
BergJC

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BergJC
BergJC

I'm sure it's not the answer you wanted,
The only way you can fill the other columns first is to simulate it by filling the first column with spaces. This, however, can get very messy and isn't very reliable. Also, when you do it this way, the user can click on the rows which contain spaces. That makes it kind of confusing.

For instance(assuming this listbox has 5 rows and 2 columns):

List.additem "First Column"
List.additem " "
List.additem " "
List.additem " "
List.additem " "
List.additem "Second Column"


I'm sure it's not the answer you wanted but,
The only way you can fill the other columns first is to simulate it by filling the first column with spaces. This, however, can get very messy and isn't very reliable. Also, when you do it this way, the user can click on the rows which contain spaces. That makes it kind of confusing.

For instance(assuming this listbox has 5 rows and 2 columns):

List.additem "First Column"
List.additem " "
List.additem " "
List.additem " "
List.additem " "
List.additem "Second Column"


If you are using the multicolumn list box from the MS Forms 2.0 Object Library - not a normal listbox - you can fill it using an array which does not require you to fill one column before filling another.  If this is what you had in mind I'll give you the code to do it.
You should not use the multicolumn option to simulate a listbox which has many columns for each row.

What you should do instead is to use the pre-defined tabulations which exist in the list box. Try:

List1.Additem "John" & chr$(9) & "Doe"
List1.Additem "Jim" & chr$(9) & "Smith"

If you want to modify the tabulation settings, then you have to use the API SendMessage.

Steve.

I agree with Steve06, you shouldn't try to use the listbox to simulate multiple rows. That's why I said it wasn't the answer you were looking for. I'd try using another control, possibly the dbGrid, for multicolumn functions.
There is a listbox control in the MS Forms Obj 2.0 that supports multiple columns.  Additionally you can specify one column as the "bound column" so when you use the listbox's value property it will automatically pick up whatever is in that column for the specified row.  You can also use different sizes for the different columns.  

This listbox does not simulate multi-columns - it supports multi-columns and is part of VB 5.0 - you just need to add the MS Forms 2.0 Obj Lib component to your toolbox.

Here is a code sample showing how to add items to the multi-column list box:

'column 1, report name
    vReportArray(0, 0) = "Report 1"
    vReportArray(1, 0) = "Report 2"
    vReportArray(2, 0) = "Report 3"
       

'column 2 Report id
    vReportArray(0, 1) = "1"
    vReportArray(1, 1) = "2"
    vReportArray(2, 1) = "3"
       
    listbox1.List() = vReportArray

Hope this helps.