Solved

listbox with columns

Posted on 2001-09-18
10
199 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
Comment Utility
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
Comment Utility
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
Comment Utility
;)
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
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
Comment Utility
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
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

 
LVL 15

Expert Comment

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

Expert Comment

by:rspahitz
Comment Utility
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
Comment Utility
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
Comment Utility
thanks man,

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

Expert Comment

by:Richie_Simonetti
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

772 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

12 Experts available now in Live!

Get 1:1 Help Now