Solved

Adding Items to Multi column listbox

Posted on 1998-10-07
7
523 Views
Last Modified: 2011-09-20
I am using a multicolumn listbox, how do I add items to each column?
0
Comment
Question by:whitej8
  • 4
  • 2
7 Comments
 
LVL 2

Accepted Solution

by:
BergJC earned 100 total points
ID: 1438702
WhiteJ8,
When you are filling the listbox (with .additem), it will not
start filling the other columns until you have filled the first column. Then it begins scrolling horizontally instead of vertically.
0
 
LVL 2

Expert Comment

by:BergJC
ID: 1438703
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"


0
 
LVL 2

Expert Comment

by:BergJC
ID: 1438704
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"


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:trillian30
ID: 1438705
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.
0
 
LVL 1

Expert Comment

by:steve06
ID: 1438706
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.

0
 
LVL 2

Expert Comment

by:BergJC
ID: 1438707
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.
0
 

Expert Comment

by:trillian30
ID: 1438708
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel Spreadsheet - Send email if certain value is selected. 14 88
VBA error replacing data 6 37
Windows 10 start screen issues 9 52
Excel Automation VBA 19 39
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now