0

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;
    }
	 
}
3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Radical Edward
0

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.

0

> 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.

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.