Solved

VB Listbox/ListView

Posted on 2014-10-13
3
99 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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.
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…
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…

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

13 Experts available now in Live!

Get 1:1 Help Now