Malfist
Malfist

Reputation: 31815

Formatting text for a combobox, C#

I have three values I need to align in a dropdown box. How can I do this? I've been trying this:

String.Format("{0,-30}{1,-15}{2,-10}{3,-8}", new object[] { cusJob, service, username, time });

But that leaves it uneven because it's not a monospaced font. I don't really want to use a monospaced font and I've seen applications align it before so how can I do it?

Upvotes: 5

Views: 9617

Answers (2)

devio
devio

Reputation: 37225

You need to set the DropDownList's DrawMode to OwnerDrawFixed and render the items in the DrawItem event handler.

Examples are here and here and here, but there are lot more to be found on the web, if you search for "dropdownlist ownerdraw columns drawmode".

Upvotes: 5

Pondidum
Pondidum

Reputation: 11637

in your string you could use the \t control char (tab) to tab out the values, although some more string-manip might need to be done to work out how many tabs you need to put in the string.

Edit: for vb.net see the controlchars class

Upvotes: -1

Related Questions