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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox column alignment

Status
Not open for further replies.

StewartUK

Programmer
Feb 19, 2001
860
GB
Other than choosing courier new as font, is there a way of getting the columns on a listbox line up correctly when the length of items is different?

For example:

Date Amount Claimed
03/12/2007 7.46 N
22/11/2007 350.00 Y

Thanks,

Stewart
 
Stewart,

Set the ColumnWidths property to a comma-delimited list of the required widths (in pixels) of each column. The actual widths are not critical -- the point is that you put some value in this property.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks, that half-worked - the columns are now a fixed width.

However, the amount columns are not aligned right. I suspect this is because they are turned into character types in the ListBox.

Is there a way around that?

Thanks,

Stewart
 
Stewart,

If you are using a cursor or an array to populate the listbox, you could explicitly convert the amount to a right-justified string, for example using TRANSFORM(Amount, "999,999.99") or something similar.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hello Mike,

Yes, I am using a cursor.

Again that kind of works. But when you look at the data in a listbox, an amount of 7.50 is offset to the left of an amount of say 55.50 - the decimal points aren't aligned. It looks like the column is left justified.

Stewart
 
Stewart,

I guess that's just a limitation of a listbox. It doesn't really support much in the way of formatting options.

Should you perhaps consider a grid for this task - unless anyone can suggest a better workaround, of course.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Ah yes, I forgot to say that I wanted the multi-select capability of the listBox :). I seem to remember seeing various posts here about doing that with grids so I might have a look.

Stewart
 
You might try building a function that prepends spaces to the display string until a certain width is met, or slightly exceeded. You can use the form's .TextWidth method to determine the length of the string given the current form's font settings. I still don't think you'll get exact, but you can get fairly close.


--------------
Good Luck
To get the most from your Tek-Tips experience, please read
FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top