0

hey guys.
i am having a problem with combo boxes in c++.
i am making a very simple game for a subject at uni, in this game you pick up guns and shoot monsters. each gun has attributes; damage range and name.
when you pick up a gun it is meant to be added to the gunSelection combo box, where u can then choose what gun you want to use. when a gun have run out of bullets it is removed from the list.
i have been adding the guns using
gunSelection->Items->Add(static_cast<gun ^>(map[nextX,nextY]));
which seems to work the only problem is in the combo box selection it labels all the guns as "gun" which is the object type. I want it to the the name attribute. Does anyone know how to specify how you want the objects to be labled in the combo box.
ie. The combo box currently looks like this
gun
gun
gun
gun

where i want it to look like this
pistol
machine gun
rifle
ect.
Any help would be greatly appreiated. cheers

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by mickmos
0

You need to implement a ToString() method in your gun class (or any other that you want to display).

You can declare it inline in the public section of the header for your class:

virtual String ^ ToString() override
{
      return name;
}

change name to whatever member of your class represents the label.

0

awsome! this is exactly what i was looking for. Thank you very much!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.