How do I open a Form using a Combobox In C++?

How do I open a Form using a combobox? If I have 3 Values such as apples, oranges and I want to open a form if the user choses apples and another form if the user choses oranges.

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

 FrenchFries ^ newfrm = gcnew FrenchFries();

 if (comboBox1::Text = "French Fries") 
newfrm->Show();

 else 
Form::Close();

This is the error that I get.

error C2451: conditional expression of type 'void' is illegal
error C2653: 'comboBox1' : is not a class or namespace name
8 hours ago
- 4 days left to answer.

Recommended Answers

All 2 Replies

Member Avatar for iamthwee

Not used c++ dotnet but I'd imagine there should be a property called:

comboBox1.name or something?

Also you need to use the double equals sign to compare strings...

==

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
             {
                FrenchFries ^ newfrm = gcnew FrenchFries();
                if (comboBox1->Text == "French Fries") 
                    newfrm->ShowDialog(this);

                else 
                    this->Close();
             }

Milton

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.