K
K
KlassT2017-04-07 01:25:31
C++ / C#
KlassT, 2017-04-07 01:25:31

How to display a field in a combobox?

There is a station object. I pass it to combobox1.Items.Add (station). Now MetroLibrary.Station is displayed, but I would like the Title field of the station object to be displayed. How to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew K., 2017-04-07
@gdi32dll

combobox1.Items.Add(station.Title)

D
Dmitry Makarov, 2017-04-07
@DmitryITWorksMakarov

first option:
if you can override the ToString() method of Station, then override it so that this method returns Title.
second option:
set the comboBox1 property to DrawMode other than Normal and use the DrawItem event handler to display whatever you want.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question