Solved

listbox with columns

Posted on 2001-09-18
10
200 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
 
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
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.

 
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

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

911 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

22 Experts available now in Live!

Get 1:1 Help Now