Solved

Adding Items to Multi column listbox

Posted on 1998-10-07
7
531 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

808 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