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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.