Solved

listbox with columns

Posted on 2001-09-18
10
203 Views
Last Modified: 2010-05-02
hey all,

need to add 2 recordset items to the same listbox.

the character length varies among the strings, but i am trying to get them to line up.

for example:

Home 800.555.1234
Office 800.555.2697

SHOULD BE....

Home          800.555.1234
Office           800.555.2697
0
Comment
Question by:jsopher
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 100 total points
ID: 6491788
Add this code to a new form that has a list box (List1):

Private Declare Function SendMessageArray Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Sub Form_Load()
Const LB_SETTABSTOPS = &H192

ReDim TabStops(0) As Long
TabStops(0) = 50    'This may need to be adjusted

'Clear any existing tabs
SendMessageLong List1.hWnd, LB_SETTABSTOPS, 0&, 0&
SendMessageArray List1.hWnd, LB_SETTABSTOPS, CLng(UBound(TabStops) - LBound(TabStops) + 1), TabStops(LBound(TabStops))

List1.AddItem "Home" & vbTab & "800.555.1234"
List1.AddItem "Office" & vbTab & "800.555.2697"

End Sub
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6491795
Since you only are calling this once, you can abreviate the following line:
SendMessageArray List1.hWnd, LB_SETTABSTOPS, CLng(UBound(TabStops) - LBound(TabStops) + 1), TabStops(LBound(TabStops))

As follows:
SendMessageArray List1.hWnd, LB_SETTABSTOPS, 1, TabStops(0)

Anthony
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6491814
;)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:rspahitz
ID: 6491928
The standard listbox does not support multiple columns, but if you set the font to Courier New (or other fixed-point font like Win2000's Lucida Console) it will be pretty easy to line things up.

Alternately, you can get a listbox that supports multiple columns, like the one that comes with Access and is part of the MS Forms 2.0 Object Library. (Note that this particular one can only be distributed with permission from MS, although you could try to write your own!)
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6491949
rspahitz,

>> it will be pretty easy to line things up <<
This is basically what the code I posted does, without the need to use Fixed Fonts.

Anthony
0
 
LVL 15

Expert Comment

by:ameba
ID: 6491960
If you already have reference to "Microsoft Windows Common Controls" component, use ListView control in Report view.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6491965
Good job, Anthony.

However, I always try to avoid API calls when not necessary, simply because they are likely to break in future versions, especially with .net looming...

In this case, they might be necessary...if you want a proportional font.
0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6492097
Have to agree with ameba on this one use a ListView control instead of a List control. No messing around with API calls, Fonts, positioning columns etc.

Vin.
0
 

Author Comment

by:jsopher
ID: 6492129
thanks man,

worked like a charm - exactly what i wanted.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6492419
Jst, optionally, you could add microsoft forms component to toolbox and use listbox from it since it has columns property.
It uses resources and i don't know if it is redistributable.
Cheers
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

733 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