Right justify column in ListBox 
Author Message
 Right justify column in ListBox

Does anybody know how to right justify one column in a ListBox ?

In fact, if you use a proportional spaced font, like Arial, any numeric
column shows its values misaligned due to the narrower space occupied by the
character space (" ") and the default left justification.

Joao



Sat, 26 May 2001 03:00:00 GMT  
 Right justify column in ListBox

Quote:
>In fact, if you use a proportional spaced font, like Arial, any numeric
>column shows its values misaligned due to the narrower space occupied by
the
>character space (" ") and the default left justification.

What about a padl()'d or transform()'d version of the numeric values as the
rowsource?
Quote:
>L<



Sun, 27 May 2001 03:00:00 GMT  
 Right justify column in ListBox
Thank you Lisa for your help.

I've done that already. I mean I've created a new column within the view
with TRANSFORM()'d of the numeric values and then used it for the column in
ListBox.

The problem is that left generated spaces do not occupy the same lenght as
regular numeric digits and, as the column is left justified, this causes the
unwanted misalignment. Just try it and see.

Joao

Quote:

>>In fact, if you use a proportional spaced font, like Arial, any numeric
>>column shows its values misaligned due to the narrower space occupied by
>the
>>character space (" ") and the default left justification.

>What about a padl()'d or transform()'d version of the numeric values as the
>rowsource?

>>L<



Sun, 27 May 2001 03:00:00 GMT  
 Right justify column in ListBox
The easiest way to get numerical column rightaligned is to leave them as
numeric in the source and use a fixed font like Courier New for the listbox
or combobox. The alignment property for a combobox only affects the textbox
part, not the dropdown list.
-Anders

Quote:

>Thank you Lisa for your help.

>I've done that already. I mean I've created a new column within the view
>with TRANSFORM()'d of the numeric values and then used it for the column in
>ListBox.

>The problem is that left generated spaces do not occupy the same lenght as
>regular numeric digits and, as the column is left justified, this causes
the
>unwanted misalignment. Just try it and see.

>Joao


>>>In fact, if you use a proportional spaced font, like Arial, any numeric
>>>column shows its values misaligned due to the narrower space occupied by
>>the
>>>character space (" ") and the default left justification.

>>What about a padl()'d or transform()'d version of the numeric values as
the
>>rowsource?

>>>L<



Sun, 27 May 2001 03:00:00 GMT  
 Right justify column in ListBox
Lisa,

This for example does not right align a column in a lst of mine:

         .maListData[i,2] = padl( transform( ceiling( .maListData[i,2] / 1024 ),
"999,999" ), 7, " " )

The lst font is Arial,9. I'd be real curious to see how you get right aligned numbers
without using a fixed pitch font. Perhaps you have a font where the display pixel width of
chr(32) == chr(48 through 57)

df    - (Microsoft FoxPro MVP) http://www.geocities.com/ResearchTriangle/9834/

Quote:

>I did try it; that's why I suggested that you use a PADL() expression on top
>of the TRANSF() <s>.  I had good results with this combination. Did you try
>it this way?

>There are definitely other factors involved.  So if you can't get it to work
>with the PADL(), can you provide a sample here with your data (I don't even
>know whether this is integers, or what) and the PADL(TRANS()) expression you
>used?  It might also make a difference exactly which proportional font
>you're using, so you should give the font attributes also, and I'll give it
>a go.



Sun, 27 May 2001 03:00:00 GMT  
 Right justify column in ListBox

Quote:
>I've done that already. I mean I've created a new column within the view
>with TRANSFORM()'d of the numeric values and then used it for the column in
>ListBox.

>The problem is that left generated spaces do not occupy the same lenght as
>regular numeric digits and, as the column is left justified, this causes
the
>unwanted misalignment. Just try it and see.

I did try it; that's why I suggested that you use a PADL() expression on top
of the TRANSF() <s>.  I had good results with this combination. Did you try
it this way?

There are definitely other factors involved.  So if you can't get it to work
with the PADL(), can you provide a sample here with your data (I don't even
know whether this is integers, or what) and the PADL(TRANS()) expression you
used?  It might also make a difference exactly which proportional font
you're using, so you should give the font attributes also, and I'll give it
a go.

Regards,

Quote:
>L<



Mon, 28 May 2001 03:00:00 GMT  
 Right justify column in ListBox

Quote:
>The easiest way to get numerical column rightaligned is to leave them as
>numeric in the source and use a fixed font like Courier New for the listbox
>or combobox. The alignment property for a combobox only affects the textbox
>part, not the dropdown list.

True, but unfortunately (1) some people don't want to use a fixed font and
(2) this is a listbox not a combobox anyway <g>.  So we're stuck with
kludges, I'm afraid...

I remember 'way back in the 3 beta complaining about alignment for numbers
in listboxes *and* combos.  The docs at one point suggested more
functionality, but I think they tossed it.  Not sure why this was difficult,
but apparently it was.

The reason I remember this was I was building my Filer substitute (remember
they took out Filer briefly in the 3 beta and then put it back in?) so I
wanted numeric columns to match, well, the Filer <g>.

One brief and odd historical note from the annals of Fox...

Quote:
>L<



Mon, 28 May 2001 03:00:00 GMT  
 Right justify column in ListBox

Quote:

>(2) this is a listbox not a combobox anyway <g>.  So we're stuck with
>kludges, I'm afraid...

My point was that comboboxes and listboxes are the same in this respect.
Listboxes don't have an Alignment property and as Combo.Alignment only
affects the combo's textbox the combo list doesn't have an Alignment
property either.

Are VB's list controls any better?

-Anders



Mon, 28 May 2001 03:00:00 GMT  
 Right justify column in ListBox

Quote:

>There are definitely other factors involved.  So if you can't get it to
work
>with the PADL(), can you provide a sample here with your data (I don't even
>know whether this is integers, or what) and the PADL(TRANS()) expression
you
>used?  It might also make a difference exactly which proportional font
>you're using, so you should give the font attributes also, and I'll give it
>a go.

Lisa,

Thank for you continued interest.
You are quite right, I didn't give enough information about the problem.
Let's try to correct this:

1. I need a ListBox displaying several text columns and one numeric column
with the style equivalent to "9,999,999,999.9" (currency like).

2. I was using Arial 8 at this point.

3. If I use the numeric value column directly in the RowSource, the column
is correctly aligned to the right but I don't get the comma style display.
It now came to my mind that I didn't try to declare the table field as
"currency".

4. I then generated another column within the view with a TRANSFORM() of the
numeric column and placed it in the RowSource of the ListBox. The
TRANSFORM() pads the string with spaces for non-exiting digits on the left
and so the values get misaligned because the number of pixels for " " are
less than for a regular digit and the character string is left justified in
the ListBox for text values.

5. I then tried a monospaced font, Courier New 8, which works but I don't
like the look of it.

To conclude, I think it would be just logical to have the possibility of
formating the columns within the ListBox, either directly in the RowSource
property string, or using a new InputMask like property, perhaps named
DisplayMask, that would work for multi-column. That's what I was looking for
and couldn't believe it didn't exist. I'm now convinced.

If you still need more data I can build a small project to reproduce this.

Thank you again

Joao



Mon, 28 May 2001 03:00:00 GMT  
 Right justify column in ListBox

Quote:

>The easiest way to get numerical column rightaligned is to leave them as
>numeric in the source and use a fixed font like Courier New for the listbox
>or combobox. The alignment property for a combobox only affects the textbox
>part, not the dropdown list.
>-Anders

Yes, but then you don't get comma style format like "9,999,999,999.9" which
is important when you have a currency like the Escudo which rates 180
against the USD. Of course this will be gone when the Euro arrives.

Furthermore, I don't like the look of Courier New on a list.

Joao



Mon, 28 May 2001 03:00:00 GMT  
 Right justify column in ListBox
Joao,

You can get the formatting with a Rowsource like this:
.ComboBox.RowSource = [SELECT payor, ;

FROM Amounts INTO CURSOR Q1]

However it won't get you right alignment unless the amount is about the same
length on most rows and you set thre columnwidths just right. You can try
other fixed fonts like Fixedsys. Even with a proportional font you'd get
pretty near with CB.ROWSOURCE = [SELECT payor,  ;

FROM AMOUNTS INTO CURSOR Q1] and cb.fontname = "Univers".
because CHR(150) takes about the same space as a digit but that again might
be an unacceptable solution.

-Anders

Quote:


>>The easiest way to get numerical column rightaligned is to leave them as
>>numeric in the source and use a fixed font like Courier New for the
listbox
>>or combobox. The alignment property for a combobox only affects the
textbox
>>part, not the dropdown list.
>>-Anders

>Yes, but then you don't get comma style format like "9,999,999,999.9" which
>is important when you have a currency like the Escudo which rates 180
>against the USD. Of course this will be gone when the Euro arrives.

>Furthermore, I don't like the look of Courier New on a list.

>Joao



Mon, 28 May 2001 03:00:00 GMT  
 Right justify column in ListBox
To everyone,

I have written an ActiveX list box called "dbfList" that solves the problem
you are discussing. To this point, we are only using it in-house, but I
would like to explore the possibility of eventually marketing it.

I am willing to send it to interested people to see if it is useful and
something that might fly as a product.

Features:

Works with arbitrarily large data tables or arrays.
Single select or multi-select.
Single column or multiple columns. Tab styles: left, right, center and
decimal.
Provides item tips for items too long to completely display.

However, there are several caveats:
Documentation is limited. At this time there is no help file.
I would be available for a limited amount of support, but there are no
guarantees.

I have an OLE container class that holds the control and provides all of the
support necessary.


David Dunetz
SweetWARE

Quote:

>Does anybody know how to right justify one column in a ListBox ?

>In fact, if you use a proportional spaced font, like Arial, any numeric
>column shows its values misaligned due to the narrower space occupied by
the
>character space (" ") and the default left justification.

>Joao



Tue, 29 May 2001 03:00:00 GMT  
 Right justify column in ListBox

Quote:
>To conclude, I think it would be just logical to have the possibility of
>formating the columns within the ListBox, either directly in the RowSource
>property string, or using a new InputMask like property, perhaps named
>DisplayMask, that would work for multi-column. That's what I was looking
for
>and couldn't believe it didn't exist. I'm now convinced.

As I said, I remember arguments about this during the VFP 3 beta.
Originally, there was no such property-per-column; however, default
alignment for a numeric column within a listbox was set to Right, whereas
char-type columns defaulted to left-alignment.  I can't remember what the
default for logical or other data types was going to be, and I don't know
exactly what happened except that they decided against implementing this.

Quote:
>If you still need more data I can build a small project to reproduce this.

No!!!!!

What I need is:

1) did you try the PADL(TRANSF())  combination that I suggested, which you
don't mention here

and

2) if you did, please repro what you did -- NOT IN A PROJECT, simply in a
couple of lines of code in a message here, such as:

CREATE CURSOR .... && if your rowsourcetype is fields or some other source
depending on a table
&& otherwise create the necessary array for your rowsource, or whatever you
need

_SCREEN.AddObject("x","listbox")
_SCREEN.x.Visible = .T.
_SCREEN.x.FontName = "Arial"
_SCREEN.x.FontSize = 8
&& _SCREEN.RowSourceType = ...
&&  proceed to give your sample
&& listbox the properties that you need
&& and I will play with it from here to
&& see if I can tweak the formatting a little
&& for you -- but for heavens' sake don't build a project
&& or add any unnecessary detail to repro your situation!

Quote:
>L<



Fri, 01 Jun 2001 03:00:00 GMT  
 Right justify column in ListBox

Quote:

>What I need is:

>1) did you try the PADL(TRANSF())  combination that I suggested, which you
>don't mention here

Lisa,

I'm sorry to be late answering, I've been away working for the past days.

I really didn't mention it but I did try PADL(TRAN(x)) but it also doesn't
work once that the left padded characters, being spaces, are narrower than
the regular digits and also cause misalignement. Furthermore there are also
narrow digits like, for instance, "1" and the negative sign "-".

By the way, just PADL is enough, you have to PADL(LTRIM(TRAN)))
Once again, I really do appreciate your commitment to help me in solving
this. I award you the Nobel for helping dumb foxes !

Please find below the statements you asked for to repro the situation.

dimension adata1(4)
store 999999.9 to adata1(1)
store 1 to adata1(2)
store 111111.1 to adata1(3)
store -99999.9 to adata1(4)
_SCREEN.AddObject("x","listbox")
_SCREEN.x.Visible = .T.
_SCREEN.x.FontName = "Arial" && With Courier New everything OK
_SCREEN.x.FontSize = 8
_SCREEN.x.RowSourceType = 5
_SCREEN.x.RowSource = "adata1"

* Now see the result and then
* Let's try your suggestion

store padl(ltrim(tran(1,"999,999,999.9")),13) to adata1(2)
_SCREEN.x.Refresh()

* As you see, it doesn't align the "1"
* but, if you use a wider character:

store padl(ltrim(tran(1,"999,999,999.9")),13,"0") to adata1(2)
_SCREEN.x.Refresh()

* It proves my point, I'm now convinced it only works with
* monospaced fonts like Courier New (which I dislike!)

Joao



Sun, 03 Jun 2001 03:00:00 GMT  
 Right justify column in ListBox
Lisa,

I've been using this technique since FPW. It has one ugly drawback that
causes the numbers to almost, but not quite, line up.

The PAD() functions use spaces to pad strings. In your example, you used
Arial 8 point. The spaces are 3 pixels wide. This means that you can only
control the TXTWIDTH of strings in increments of 3 spaces. So whenever you
do this, there will be an error of 0, 1 or 2 pixels.

0 is ok, but errors of 1 or 2 pixels cause the strings to slightly misalign.
This is why I have always wished that font designers would create a 1-pixel
space character so this technique would work perfectly.

I finally got fed up with ugly looking list boxes, which is why I broke down
and finally designed my own list box.

David Dunetz
SweetWARE

Quote:

>OK, Joao, I 've done this.

>It's not entirely perfect, because I am slightly relying on the fact that
>all digits are the same width, even in proportional fonts, whereas a more
>finely-pointed strategy would be more careful about the "." and "-" widths.

>However, I think you will see the results you want, or at least understand
>how to go about getting them, if you try the following:

>**** runnable code starts here
>clear all
>public adata1[1], iDesiredWidth
>dimension adata1(4)
>store 999999.9 to adata1(1)
>store 1 to adata1(2)
>store 111111.1 to adata1(3)
>store -99999.9 to adata1(4)
>_SCREEN.AddObject("x","listbox")
>_SCREEN.x.Visible = .T.
>_SCREEN.x.FontName = "Arial" && With Courier New everything OK
>_SCREEN.x.FontSize = 8
>_SCREEN.x.RowSourceType = 5
>_SCREEN.x.RowSource = "adata1"

>iDesiredWidth = txtwidth("999,999,999.9","arial",8)
>iDesiredWidth = iDesiredWidth * ;
>   (txtwidth("0","arial",8)/txtwidth(SPACE(1),"arial",8))
>LOCAL ii,xx, yy
>for ii = 1 TO ALEN(adata1)
>   xx = ltrim(tran(adata1[ii],"999,999,999.9"))
>   yy = txtwidth(xx)/txtwidth("0","arial",8)
>   store padl(xx,iDesiredWidth-yy) ;
>       to adata1[ii]
>endfor
>_SCREEN.x.Refresh()

>**** end runnable code

>You can use the form.textwidth() function instead of txtwidth() if you
>prefer -- you just have to set the form.fontname and other font attributes
>to match your listbox first -- because you can then avoid passing the font
>properties each time you need the function.

>>* It proves my point, I'm now convinced it only works with
>>* monospaced fonts like Courier New (which I dislike!)

>I don't know if "it works with" is the right "point", here.  The right
>"point" is "can you do it if you care enough about it <g>?" In my case,
>frankly, I'd use Lucida Typewriter (my favorite monospaced font) and forget
>the whole problem I guess.  But you *can* do the above if you prefer.  I
may
>not have it perfectly right, but I'm sure you'll see the implications.

>Some other points: the general technique should work the same way with any
>fonts (IOW it's not due to any peculiarity of Arial or 8 point size).  You
>just have to make sure that they match up (the calculations have to be done
>for the same font you're using).

>However, you would be wise to check your columnwidth and try to get it (as
>well as the listbox width) to match your desired width properly, so that
the
>entire number shows.  Otherwise, as you change the font properties, your
>full numbers will not show up, they are going to be off to the right in
>larger fontsizes or wider fonts.

>>L<



Mon, 04 Jun 2001 03:00:00 GMT  
 
 [ 22 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Right-Justify SAY?

2. Right justified auto-trimming??

3. How to right justify menu bars in vfp6 ?

4. Right Justify Screen Font?

5. Report Form - Left and Right Justify

6. numeric field, making commas static (right justify input)

7. Grid - can't scroll right depending on column widths

8. Right Click to hide grid columns

9. Right click on grid column header

10. Right-alignment problem of Numeric data in LISTBOX

11. Right-alignment problem of Numeric data in LISTBOX

12. Multi-column listboxes are picky?

 

 
Powered by phpBB® Forum Software