Right-justify ListBox items? Is this possible?

donaldc104

Active member
Joined
Jan 4, 2003
Messages
32
Is it possible to right-justify the items in a ListBox?

The Label has a property called TextAlign. But I cant find any alignment for the ListBox. I only need Left-or-Right alignment.

I tried to use a space-padded Format like this:
Code:
 lstList1.Items.Add(Format(dNumber, "0,-10:C "))
but could not get it to work (space-padding refused to appear).

Does anybody know a trick that I could use?

- donaldc104
 
I tried the RightToLeft property (set to True) and that worked.

I cant say Ive ever seen a ListBox that was right-aligned though. What kinds of data are you putting in the listbox? Could you use some other control, maybe?

-Nerseus
 
RightToLeft right-justifies ListBox items.

It works ! The RightToLeft property right-justifies OK. I thought this property was for Hebrew or Arabic languages.

Im displaying columns of numbers, and it looks better if the larger values stick out. See attached image.

Unfortunately, setting {RightToLeft = True} also moves the scroll bars to the left side of the box. But I can work around that.

I first tried using a DataGrid. I like its display better, but it is so complex (you must drag along an entire data base, etc). Is there some other control you would recommend ?

Thanks for the tip ! :D
 
Normally a DataGrid would be more "standard" but nothing says you cant use whatever control you like. I do see what you mean with the DataSet and DataGrid being a bit more cumbersome than a simple listbox. You could use an ArrayList for the DataGrid, but youd have to define a custom object to put in there so that the Grid displayed what you want.

And youre right about the RightToLeft property. Its purpose is for different languages, not for string formatting. But a ListBox wasnt meant to hold right-aligned text (that Ive ever seen) so it worked well :)

Im not sure how many numbers youre displaying, but I can think of two other alternatives. A multiline textbox (readonly) might work. You could also try a ListView. Its a tad bit more work than a listbox but might be worth it.

Good Luck!

-Nerseus
 
ListView will work OK

Thanks for the tip on the ListView !
I had previously eliminated it as a possibility, based on the documentation that Id read. But when I read your suggestion, I researched it deeper. It appears that it will do the trick for my program.
ListView is sparsely (poorly) documented but its an amazingly flexible control. DataGrid is better documented but its not a match for me.
 
Back
Top