C# ShowDialog inside of ShowDialog closing both on return

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • Wojciech Jankun
    replied
    Originally posted by michaelp
    I had a very similar issue. I constructed a UserControl that would basically drive a whole form that you placed it into. When ever I would do a ShowDialog on it, it would appear then disappear. Really fast I might add. It was driving me up the wall until I ran across this thread. Good Job.
    I did Aps that all widnows using same code. In more less half of them Described issue appears and I had to use this.DialogResu lt=DialogResult .None and in other half it was working OK without it.

    I guess it's some serious bug in .NET

    Leave a comment:


  • michaelp
    replied
    I had a very similar issue. I constructed a UserControl that would basically drive a whole form that you placed it into. When ever I would do a ShowDialog on it, it would appear then disappear. Really fast I might add. It was driving me up the wall until I ran across this thread. Good Job.

    Leave a comment:


  • NVergunst
    replied
    Ok, solution found:

    The Ok was being passed down and I dont know why. But if after the .ShowDialog() I just have to put this.DialogResu lt = DialogResult.No ne, and it will fix it. This shouldnt happen in the first place, but this fixes it, so I am not too bothered.

    Leave a comment:


  • NVergunst
    replied
    No dialog result on the second form.

    I have this button click handler on the Main Form:

    Code:
            private void TSB_AddBrain_Click(object sender, EventArgs e)
            {
                if ((new BrainForm()).ShowDialog(this) == DialogResult.OK)
                {
                    //Add it to the main list
    
                }
            }
    and then on "BrainForm"
    Code:
            private void BTN_SEARCHBRAIN_Click(object sender, EventArgs e)
            {
                (new AutoSearchBrains()).ShowDialog();
            }
    and then on AutoSearchBrain Form (OK and Canel Buttons)

    Code:
            #region Cancel Button Clicked
            private void BTN_CANCEL_Click(object sender, EventArgs e)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
            #endregion
    
            #region Save Button Clicked
            private void BTN_SAVE_Click(object sender, EventArgs e)
            {
                this.DialogResult = DialogResult.OK;
                if (LISTBOX_AllBrains.SelectedItem != null)
                {
                    SendAutoBrain(FoundBrains[LISTBOX_AllBrains.SelectedIndex]);
                }
                else
                {
                    ErrorForm _tempError = new ErrorForm("Select a Fusion Brain", "Please Select a Fusion Brain Instance from the list");
                    _tempError.ShowDialog();
                    return;
                }
                this.Close();
            }
            #endregion

    It must be a setting somewhere, because if I error it and make ErrorForm appear, I can close it no problem... But again if I close AutoSearch form, BrainForm closes too regardless of the DialogResult.

    What sort of setting would cause a fall through like this? Would it have to do with the button's having the same name but on different forms? All cancel buttons are named "BTN_CANCEL " and all OK buttons are "BTN_SAVE". Perhaps the event handlers are using the button name as the event trigger and not its instance or something?

    Leave a comment:


  • wimpos
    replied
    I tried what you tried and I'm not having your issue.

    what I did
    Form1 with button to open Form2
    Form2 with button to open Form3
    Form3 with button to set diaglogresult to Cancel

    If fire my app, Form1 opens, I press the button, Form2 opens, I press the button Form3 opens, I press the button Form3 closes. Form2 remains open.

    Form1:
    Code:
    private void button1_Click(object sender, EventArgs e)
    		{
    			(new Form2()).ShowDialog();
    		}
    Form2:
    Code:
    private void button1_Click(object sender, EventArgs e)
    		{
    			(new Form3()).ShowDialog();
    		}
    Form3:
    Code:
    private void button1_Click(object sender, EventArgs e)
    		{
    			this.DialogResult = DialogResult.Cancel;
    		}
    You must 've done someting wrong. Do you set a dialogResult on the second form?

    Regards

    Leave a comment:


  • r035198x
    replied
    Originally posted by NVergunst
    I have a main form, then this form spawns another form (Form A) as a form.showdialog (). That dialog box then has a button that spawns another form (Form B) through the form.showdialog (). All of this works fine.

    Now when I press a button on Form B, and set the "this.DialogRes ult = DialogResult.Ca ncel", then close, it goes back to FormA, and Form B closes. Then Form A closes and returns to the main form. This is not what I am wanting.

    I want Form A to stay open. It seems like the DialogResult is being sent back through all the forms... How can I prevent this?
    Perhaps you are using Dialog boxes where you ought to be using normal forms ...

    Leave a comment:


  • C# ShowDialog inside of ShowDialog closing both on return

    I have a main form, then this form spawns another form (Form A) as a form.showdialog (). That dialog box then has a button that spawns another form (Form B) through the form.showdialog (). All of this works fine.

    Now when I press a button on Form B, and set the "this.DialogRes ult = DialogResult.Ca ncel", then close, it goes back to FormA, and Form B closes. Then Form A closes and returns to the main form. This is not what I am wanting.

    I want Form A to stay open. It seems like the DialogResult is being sent back through all the forms... How can I prevent this?
Working...