Solved

VB Listbox/ListView

Posted on 2014-10-13
3
110 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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