Reputation: 1435
I would like a dropdown list (comboBox) that displays not just one column but two (or more).
I have seen examples that concatenates two values to one, and just displays that. But that is a bit ugly. The separator between the two values wont line up at column boundaries, when you have text of different length in the list. Therefore I would like to avoid concatenating, and actually display two separate values in two separate columns. How do I do this?
Ugly:
Johnnie | Doe
John | Smith
Nice:
Johnnie | Doe
John | Smith
Edit: I went with a ListView instead of a dropdown list. It supports multiple columns cleanly.
Upvotes: 0
Views: 1369
Reputation: 662
You would have to build the combobox programmatically and have the strings written out (or build a custom method to do so) in such a way that your divider is always at the same location.
Probably something like get the longest length of first name, add 1, then do a string replace with enough spaces to fill before the separator in each name that is shorter.
Upvotes: 1
Reputation: 2940
You'll have to do an ownerdraw for this ... see ComboBox.DrawMode Property for an example of how to go about it.
Upvotes: 1