You don't have to add objects of the type
string
to the list box
Items
— they can be of any type. More than that, I recommend to use some semantically descriptive types instead of strings, as you will likely need some information on the item when you work with its selection, etc.
It leaves just for one problem: what text will be displayed in the items? The solution is simple: in the type of the item, override the method
ToString
as the value returned by this function is the value shown in the list box.
Problem solved.
[EDIT]
Please see my past answer where I complied several past answers on related problems, with source code samples applicable to
ComboBox
and
ListBox
:
combobox.selectedvalue shows {} in winform[
^].
—SA