Solved

Adding Items to Multi column listbox

Posted on 1998-10-07
7
516 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

17 Experts available now in Live!

Get 1:1 Help Now