I'm building a value to display in a dropdown Select box. This value consists of a currency value, then a username. What I would like is that the usernames all start with the same indent.
Ex (what I have currently):
$1,000 UserA
$100 UserB
$10 UserC
What I would like:
$1,000 UserA
$100 UserB
$10 UserC
or even better:
$1,000 UserA
$100 UserB
$10 UserC
As I see the third list as the most readable.
Is there an easy way to do this without writing a function where I examine the max length, and then format it manually or a "cheat" to accomplish this?
Edit: How I generate the ViewModel items (what I pass to my Webpage)
public ActionResult SearchCollections()
{
SearchCollectionGridViewModel scgvm = new SearchCollectionGridViewModel();
var UserNamesWithValues = (from ud in db.userdetails //build the dataset to pass to the View
join usr in db.my_aspnet_users on ud.IdUsers equals usr.id
select new {
UserName = usr.name,
TradeCollectionValue = ud.TradeCollectionValue,
NumberOfTrades = ud.NumberOfTrades,
DollarValueTraded = ud.TradeValue
}).ToList();
scgvm.TradeCollectionValues = (from c in UserNamesWithValues
where c.TradeCollectionValue > 0
orderby c.TradeCollectionValue descending
select new SelectListItem
{
Text = String.Format("{0,5} {1}", c.TradeCollectionValue, c.UserName).Replace(" ", "\xA0"),
Value = c.UserName
}).ToList();
return View(scgvm);
}
Edit #2: Answer found /figured out
I used the answer below plus the following two links to generate a string that was accurate in the Selectbox: (Monospace font will be a key as well)