Reputation: 67
So i'm trying to format the output of a listbox. Basically I want the name of the item left aligned and the cost of the item right aligned. Here is my ToString() method that i'm using:
public override string ToString() {
return String.Format("{0, -20}{1, 10:C2}", name, cost);
}
Then here is a picture of what the resulting output is doing:
Am I missing something simple here? From everything I've read this should format my output properly. I've read some stuff about using ListView instead however for the assignment I'm required to use a ListBox. Any help would be appreciated!
Upvotes: 0
Views: 575
Reputation: 66439
You just need to set the font of the control to something with a fixed-width.
listBox1.Font = new Font(FontFamily.GenericMonospace, 10);
listBox1.Font = new Font("courier", 10);
Upvotes: 1