473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.DialogResult = DialogResult.Cancel", 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?
Feb 11 '08 #1
6 32684
r035198x
13,262 8TB
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.DialogResult = DialogResult.Cancel", 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 ...
Feb 11 '08 #2
wimpos
19
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:
Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             (new Form2()).ShowDialog();
  4.         }
Form2:
Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             (new Form3()).ShowDialog();
  4.         }
Form3:
Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             this.DialogResult = DialogResult.Cancel;
  4.         }
You must 've done someting wrong. Do you set a dialogResult on the second form?

Regards
Feb 11 '08 #3
No dialog result on the second form.

I have this button click handler on the Main Form:

Expand|Select|Wrap|Line Numbers
  1.         private void TSB_AddBrain_Click(object sender, EventArgs e)
  2.         {
  3.             if ((new BrainForm()).ShowDialog(this) == DialogResult.OK)
  4.             {
  5.                 //Add it to the main list
  6.  
  7.             }
  8.         }
  9.  
and then on "BrainForm"
Expand|Select|Wrap|Line Numbers
  1.         private void BTN_SEARCHBRAIN_Click(object sender, EventArgs e)
  2.         {
  3.             (new AutoSearchBrains()).ShowDialog();
  4.         }
  5.  
and then on AutoSearchBrain Form (OK and Canel Buttons)

Expand|Select|Wrap|Line Numbers
  1.         #region Cancel Button Clicked
  2.         private void BTN_CANCEL_Click(object sender, EventArgs e)
  3.         {
  4.             this.DialogResult = DialogResult.Cancel;
  5.             this.Close();
  6.         }
  7.         #endregion
  8.  
  9.         #region Save Button Clicked
  10.         private void BTN_SAVE_Click(object sender, EventArgs e)
  11.         {
  12.             this.DialogResult = DialogResult.OK;
  13.             if (LISTBOX_AllBrains.SelectedItem != null)
  14.             {
  15.                 SendAutoBrain(FoundBrains[LISTBOX_AllBrains.SelectedIndex]);
  16.             }
  17.             else
  18.             {
  19.                 ErrorForm _tempError = new ErrorForm("Select a Fusion Brain", "Please Select a Fusion Brain Instance from the list");
  20.                 _tempError.ShowDialog();
  21.                 return;
  22.             }
  23.             this.Close();
  24.         }
  25.         #endregion
  26.  

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?
Feb 11 '08 #4
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.DialogResult = DialogResult.None, and it will fix it. This shouldnt happen in the first place, but this fixes it, so I am not too bothered.
Feb 16 '08 #5
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.
Mar 4 '08 #6
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.DialogResult=DialogResult.None and in other half it was working OK without it.

I guess it's some serious bug in .NET
Apr 4 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Richard L Rosenheim | last post by:
I would like to detect when a form is invoked as the result of a ShowDialog call. Anyone have any ideas or suggestions on how to do that? TIA, Richard Rosenheim
3
by: RubiconXing | last post by:
Hi All Beginner question - please be patient with me :-) I am new to c#. If one creates a child modal (and also non-modal) form what is the best way of returning the collected data back to the...
2
by: Nenad Dobrilovic | last post by:
Hi, is there any way to find out how form was closed (by calling it's method Close() or by clicking on the 'close' button in control box)? Also, can I close the form in that way that Cloing/Closed...
1
by: Carlos Lozano | last post by:
Hi, The default behavior for Modal forms does not restrict it to go out of the client area of the main MDI container form. I would like to show a modal form and keep it within the application...
4
by: Mike | last post by:
Hi, I already asked such question and also got some comments but when I added details - no more responds. Ok, here the story: Main form starts the additional thread. The thread contain such...
2
by: Wardeaux | last post by:
All, I have login form used with ShowDialog(). I have the AcceptButton property set so that the "Enter" key is mapped. I also need to keep the dialog open when the UserID and PWD are invalid so...
2
by: sylvain | last post by:
is there a simple way to detect a web window closing when the user hit the X of the browser ? I want to display a message to the user when he goes out of my web page. I try to detect it by using...
3
by: =?Utf-8?B?UGhpbA==?= | last post by:
I have a modal form (ShowDialog()) that I may want to close when a user clicks a button. I already have an OK and Cancel button, so I can't use those options, but I want it to function just like...
5
by: ponvijaya | last post by:
Hi all, My project is done in Tomcat 5.0 with Mysql 5 as backend. Through tomcat admin console i have configured datasource named "mine" with all the attributes needed to connect to MySql like...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.