Jamesbraders
Jamesbraders

Reputation: 143

Winforms Individually Format Double Values in ComboBox

I need to individually format items in a combo box in C#/Winforms. The combo box contains a set of doubles taken from a set of objects assigned to it (e.g., 1, 1.01, 1.02, 1.03 etc.)

What I need to do is format them so that the read (1.0, 1.01, 1.02, 1.03 etc.) not (1.00, 1.01, 1.02 etc.)

I know that the format string property can be used to format the whole collection, but is there a way to do some form of conditional formatting on the item collection by crating a user control?

Upvotes: 1

Views: 978

Answers (1)

David Heffernan
David Heffernan

Reputation: 613053

You can format each item individually by supplying a handler for the Format event.

The event handler looks like this:

private void comboBox1_Format(object sender, ListControlConvertEventArgs e)

You can then modify e.Value as you so wish.

Upvotes: 1

Related Questions