Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB Listbox/ListView

Posted on 2014-10-13
3
Medium Priority
?
113 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 2000 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

Independent Software Vendors: 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!

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

824 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