Reputation: 47
I've got quite tricky problem with my GUI application. I want my combobox to contain objects of a class I created, but at the same time it should display it's variable as name in the combobox.
This is how I add items to combobox:
publisherBox.Items.Add(p);
This is how I need to access it:
(Publisher)publisherBox.SelectedItem
And show in the combox it's name:
publisher.Name or something like that.
Is there any way it can be done?
Upvotes: 0
Views: 49
Reputation: 77374
The ComboBox will use the ToString() method to display text. You can overwrite your ToString method in your class to show the name for example.
Upvotes: 1