MessageBox, more than one when executing code

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



MessageBox, more than one when executing code



I am creating a code in Visual Studio C# and when I execute my code I get to a section where I have a Messagebox pop up to confirm if you want to change a value. At this point a 2nd MessageBox will proceed the first. Does anyone have any ideas on how I can eliminate that 2nd box?



For note: I had this error in a past code I made but it would continuously increase the number of boxes every time I reset the code because the control was called in one of my Initialize methods that got called on start, the error I am having is always two MessageBoxes consistently



EDIT: It's the same messagebox that's showing up directly after itself.



Example of code where I use the MessageBox and get the problem:


private void comboBoxReprint_SelectedIndexChanged(object sender, EventArgs e)

DialogResult result = MessageBox.Show(
"Change Reason to: rn" comboBoxReprint.Text + "rnrn" + "Confirm?",
"Label Reprint Reason",
MessageBoxButtons.YesNo, MessageBoxIcon.Information);

if (result == DialogResult.Yes)

Console.WriteLine("PROCEED WITH PROCESS");


//Grab the selection so I can save it
string _reason = (string)comboBoxReprint.SelectedItem;


//move forward in the flowchart.
if (MODE == "B")

//SAVE BAG REPRINT REASON TO DB TABLE;
//Get time in this moment.
string _time = DateTime.Now.ToString("h:mm:ss tt");
//InsertData(ID, _reason, "LabelReprintReasonBag");


else if (MODE == "P")

//SAVE PACK REPRINT REASON TO TABLE;
//InsertData(ID, _reason, "LabelReprintReasonPack");


comboBoxReprint.Enabled = false;


//Proceed to section B of flowchat.
if (MODE == "B")

QueryTestPresCheck();


else if (MODE == "P")

//Run Query for Bagging VI result *************************************************************************************************
//SelectData(_LN, _SN, "BAGGING_VI_RESULT");


else if (result == DialogResult.No)

comboBoxReprint.ResetText();






I believe we may need to see the entirety of comboBoxReprint_SelectedIndexChanged and/or if you call that method anywhere else manually. I'm guessing (blindly) that the latter may be happening.
– gravitymixes
Aug 8 at 18:03


comboBoxReprint_SelectedIndexChanged





You need to share the complete code of comboBoxReprint_SelectedIndexChanged
– Chetan Ranpariya
Aug 8 at 18:06


comboBoxReprint_SelectedIndexChanged





So where's the code for the second message box
– Yasiru Nayanajith
Aug 8 at 18:10





Have you tried to run this code under a button press event? I am willing to bet that your issue is that the method you are trying to do this in is called more than once every time you use the control that causes this. I have seen this problem many times before.
– SJ10
Aug 8 at 19:25





Not wanting to state the obvious but have you set a breakpoint on the .Show call and look at the stack trace each time the breakpoint is hit? At the very least it should tell you what is triggering the calls.
– Dunk
Aug 8 at 22:01










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS