Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Align the data in listbox - How to do?

Status
Not open for further replies.

majordog

Programmer
Jul 8, 2002
222
CA
Hi,
I add two items to each line in a list box. The first is of variable lengths, the second is a date. It looks very messy and I would like to add spaces to the end of the first item (as many as required for each specific line) to align all the date values. Below is the code I am starting with - Can anybody help me with this? Thanks!


For intCounter = 0 To rs.RecordCount - 1
intFormatColumns = 25
intFormatColumns = (intFormatColumns - Len(rs!Name))

strTempString = rs!Name
lstBotLocs.AddItem strTempString
strTempString = strTempString & " : " & rs![Date]
lstBotLocs.AddItem strTempString
lstBotLocs.ItemData(intCounter) = rs!Bottle_LocationID

rs.MoveNext
Next intCounter

 
Hi,

I had this stored away, unfortunatly i dont have the url.

Using this you can set fixed columns in a listbox.

Public Const LB_SETTABSTOPS As Long = &H192
Public Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long

Public Sub DoTabs(lstListBox As ListBox, TabArray() As Long)
'clear any existing tabs

Call SendMessage(lstListBox.hWnd, LB_SETTABSTOPS, 0&, ByVal 0&)
'set list tabstops
Call SendMessage(lstListBox.hWnd, LB_SETTABSTOPS, _
CLng(UBound(TabArray)) + 1, TabArray(0))
End Sub

' First, set up the columns:

Dim Tabs(2) As Long
Tabs(0) = 0
Tabs(1) = 100
Tabs(2) = 200
DoTabs List1, TabsThen, add your items:

' Then add items
List1.AddItem "John" & vbTab & "Percival" & vbTab & "Content Editor"
List1.AddItem "James" & vbTab & "Limm" & vbTab & "Senior Editor"
 
Unless you are using a fixed font, adding spaces won't do much good.

You should add a TAB ( or two ) in-between the items instead. vbTab or CHR$(9), either one will work. A little trial and error may be needed here. Depends on how much variance you have in string sizes for strTempString.

strTempString = strTempString & vbTab & rs![Date]

There's also ways to set the tab stops in the listbox. Do a search on that if you need it.


Robert
 

And adding vbTab will not work either if the length of the first element is too long...

The fm20.dll works nice for this.
And so does the VB ListView.
[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top