Solved

VB Listbox/ListView

Posted on 2014-10-13
3
108 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - TypeInitializer Error 25 31
Help with preventing downloading a zip file 10 45
VB.NET 2008 - Windows Protected Your PC 7 41
Visual Studios 1 76
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…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

792 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