Reputation: 510
Given:
String course = String.Format
(
"{0}-{2} {1} {3} {4} {5}",
c.course_ID.ToString().Trim(),
c.course_Name.Trim().PadRight(20),
c.Section_Num.ToString().Trim(),
c.Start_Time.ToString().Trim(),
c.Quarter.Trim(),
c.Year.ToString().Trim())
);
I have this output:
"150-2 FF Test 11:59:00 Winter 2016"
"314-1 Test Course 11:59:00 Winter 2016"
However, when these are then added to a combobox, the second line is always two spaces longer than the previous line.
combo_box.Items.add(course);
"150-2 FF Test 11:59:00 Winter 2016"
"314-1 Test Course 11:59:00 Winter 2016"
Any suggestions on how to fix this?
Upvotes: 0
Views: 123
Reputation: 1504
The problem is one of font widths. The default font for a Combo box is MS Sans Serif, which is a variable-width (or proportional) font. Each character takes up a different amount of space.
Switching to a monospaced (or fixed-width) font such as Courier New should solve your problem:
Upvotes: 1