Solved

VB Listbox/ListView

Posted on 2014-10-13
3
106 Views
Last Modified: 2014-10-17
Hi

For reasons to long to explain I have a listView  that only allows 2 Columns 1 is hidden so it displays 1
I need to display 3

I am using
s = 'Testing 1'
s = string.format("{0,-50}", s)
k = s
s = '23/10/2014'
s = string.format("{0,-22}", s)
k = k + s
s = '01/04/2015'
s = string.format("{0,-12}", s)
k = k + s
Categorieslist.add(1,k)
do the same for next record but depending on the lettering Capitals etc the two records are out of align is there a way to get them to line up

e.g

AAAAA  12/10/2014  
WWWW  12/10/2014
Even though there are 4 characters they don't align
0
Comment
Question by:Kevinfeening
  • 2
3 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40378737
Are you concerned about how  the results are displayed?

This will depend on the display context and the font used. Most will respect the relative widths of characters, giving more space to a 'w' or an 'm' than to an 'i' (lower case 'L'), for example.

In general, you need to choose a fixed-width font, such as 'New Courier' or to separate your fields with a 'tab' character.
0
 

Author Comment

by:Kevinfeening
ID: 40378808
yes I would like the fields to line up

WWWW  12/10/2014
aaaa  12/10/2014

This listview is custom control with no option to change font and using the Tab character chr(9)  show error not defined
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40379534
You could try padding the gap with enough spaces to fill out to the maximum width. This code for a standard listview demonstrates the principle:
Private Sub Command1_Click()
Dim i As Integer
Dim s As Integer
Dim e As Integer
Dim sngMaxWidth As Single
Dim Entry() As String
Dim Entries(3) As String

Form2.Font.Name = ListView1.Font.Name
Form2.FontSize = ListView1.Font.Size

Entries(0) = "AAAAA 12/10/2014"
Entries(1) = "WWWW 12/10/2014"
Entries(2) = "MMMM 12/10/2014"
Entries(3) = "IIII 12/10/2014"
s2 = "WWWW 12/10/2014"

For i = Asc("A") To Asc("Z")
    If Form2.TextWidth(String(4, Chr(i)) & " ") > sngMaxWidth Then
        sngMaxWidth = TextWidth(String(4, Chr(i)) & " ")
    End If
Next i

For e = 0 To 3
    Entry = Split(Entries(e), " ")
    s = 1
    Do Until Form2.TextWidth(Entry(0) & String(s, " ")) >= sngMaxWidth
        s = s + 1
    Loop
    ListView1.ListItems.Add , , Entry(0) & String(s, " ") & Entry(1)
Next e
End Sub

Open in new window

0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 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