Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox and spacing? Str spacing/placement?

Status
Not open for further replies.

networkthis

Programmer
Jul 11, 2011
29
US
I have a listbox that is utilizing the control source to pull in 3 different fields from a table. Each field is a defined length. The problem is that when the list is dynamically generated the dropdown items do not line up evenly unless we switch it to Courier new font that has even character spacing - which looks terrible.

So for instance we would have a display like this:
V1 V2 V3
------------------------------------------------------------
12345 WW Description # 1
45678 B1 Descrition # 2
99888 A3 Description # 3

V1, V2, & V3 are all using Pad R to put the same number of spaces after V1 and V2.
So the problem I am seeing for instance is that txtwidth of a WW = 3.4 where as an A1 = 2.2.
Is there a way to define exaclty where each Value would begin by pixel or something, so that they would all line up nicely?
 
You are encountering the standard problem resulting from the use of Proportional Fonts.

In one of the Proportional fonts a "W" is wider than an "I" and it applies throughout the range of characters.

While I don't know the list of applicable fonts off the top of my head, if you want to resolve this, use a Non-Proportional font to display your entries. With this approach the character-to-character spacing within a word may look strange, but all words of a common character count will be the same pixel length.

Good Luck,
JRB-Bldr
 
instead of a listbox you could use a grid.

The .allowcellsection property enables the user to select a row much as they would with a listbox.
You can also set .gridlines to 0 to get rid of the lines.


Plus you get column headers if you want them.


hth

Nigel
 
Thanks JRB, that's what I was afraid of :-/

Nigel, that is exactly what I was jusy trying and I think the .allowcellselection may be the new answer I was looking for!
 
Well, after creating a grid to do this.... I was playing with the list box some more and it turns out at least in VFP 9 this can be resolved easily by creating columns for each field in the list box using:

.columncount
.columnwidth
.columnlines

Just incase anyone else runs into the same issue :/

You can even do this through the builder for list boxes and combo boxes. Maybe I should have tried that first :)
 
Networkthis,

I have to disagree with Nigel (for once).

Don't switch to a grid. Stay with your original listbox.

All you have to do is to set he ColumnWidths property. It should contain a comma-delimited list of the desired column widths, in pixels. For example:

Code:
this.ColumnWidths = "30,40,45"

Obviously you will have to adjust the numbers to suit, which might involve a bit of trial and error.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top