I am trying to make something work but are not sure what I am doing wrong.
I have a comboBox where I will select an Item with the eventhandler below.

When I select an Item I want the messageBox to show a message Once but the message
is showing over and over again.
What I am after is that everytime I change Item in the comboBox1 the messageBox will appear once.
I am trying to save the comboBox->Text into a private: String for comparison but this does not seems to work. I don´t know if there could be any idéas.

private: String^ SavedItem1;

private: System::Void comboBox1_SelectedValueChanged(System::Object^  sender, System::EventArgs^  e) 
{
 
    if(SavedItem1 != comboBox1->Text)
    {
	MessageBox::Show("Show Text");
	SavedItem1 = comboBox1->Text;
    }
	 
}

You can not put MessageBox() or AfxMessageBox() inside event handler functions because they behave as you have found -- resursive. Its unfortunate, but that's the way MFC works.

> the message is showing over and over again.
There isn't anything in the code you posted that would cause that. Edward's guess is that the event is getting fired where you don't expect it, but it's hard to tell without more code.

> I am trying to save the comboBox->Text into a private: String for comparison
There's no need to do that. The event won't be fired if you select the same value that was selected previously.

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.