donaldc104 Posted January 11, 2003 Posted January 11, 2003 Is it possible to right-justify the items in a ListBox? The Label has a property called TextAlign. But I can't find any alignment for the ListBox. I only need Left-or-Right alignment. I tried to use a space-padded Format like this: 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 Quote
*Experts* Nerseus Posted January 12, 2003 *Experts* Posted January 12, 2003 I tried the RightToLeft property (set to True) and that worked. I can't say I've 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 Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
donaldc104 Posted January 12, 2003 Author Posted January 12, 2003 RightToLeft right-justifies ListBox items. It works ! The RightToLeft property right-justifies OK. I thought this property was for Hebrew or Arabic languages. I'm 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 Quote
*Experts* Nerseus Posted January 13, 2003 *Experts* Posted January 13, 2003 Normally a DataGrid would be more "standard" but nothing says you can't 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 you'd have to define a custom object to put in there so that the Grid displayed what you want. And you're right about the RightToLeft property. It's purpose is for different languages, not for string formatting. But a ListBox wasn't meant to hold right-aligned text (that I've ever seen) so it worked well :) I'm not sure how many numbers you're displaying, but I can think of two other alternatives. A multiline textbox (readonly) might work. You could also try a ListView. It's a tad bit more work than a listbox but might be worth it. Good Luck! -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
donaldc104 Posted January 16, 2003 Author Posted January 16, 2003 ListView will work OK Thanks for the tip on the ListView ! I had previously eliminated it as a possibility, based on the documentation that I'd 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 it's an amazingly flexible control. DataGrid is better documented but it's not a match for me. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.