Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combobox display issue Visual Studio 2010 C++

Status
Not open for further replies.

CUBALIBRAS

Technical User
Jan 31, 2003
64
US
I am not new to programming but am new to Visual Studio and am having problems doing the most basic of things, and for two days I have search for the answer with no success.

Here's what I'm doing:

Visual Studio 2010 usual Visual C++
Windows Forms

I have designed my form and most things work well but I am having trouble with combobox. Here is my code:

private: System::Void comboBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {


comboBox1->Items->Add("Gold");
comboBox1->Items->Add("Silver");
comboBox1->Items->Add("Oil");
comboBox1->Items->Add("US $");
comboBox1->Items->Add("Euro");
comboBox1->Items->Add("British Pound");
comboBox1->Items->Add("Yen");
comboBox1->Items->Add("Australian $");
comboBox1->Items->Add("Canadian $");
comboBox1->Items->Add("Swiss Franc");

}

What I'm trying to achieve is when a user selects one of the options it then updates a label 'ticker' with the appropriate symbol, ie GLD for Gold, and I would like to do this in the 'ticker' object using a switch statement but not only can I not find the correct syntax but my combobox has no values in it, the program compiles with no errors so I am really confused.

I can display them using the 'Items / collections' tool in its properties but then I can't manipulate the data.

If anyone has a solution or a better method in which to achieve this pleas elet me know as I have no more hair to pull out !

Thank you,
 
This looks more like C# than C++, but in either case are you adding the values to the combobox at design time?

If not, then your combobox will not contain any items until you change the selection of the combobox, which you can't do until you have items to select from.....

Somewhere, you have to have a form initialization function, for example in MFC you might use OnInitDialog in a dialog based application in which you would execute all the comboBox1->Items->Add statements.

Once the control is initialized, then your SelectedIndexChanged function would allow you to fined the value of the selected index in order to update the "ticker".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top