473,498 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# ShowDialog inside of ShowDialog closing both on return

18 New Member
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 32694
r035198x
13,262 MVP
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 New Member
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
NVergunst
18 New Member
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
NVergunst
18 New Member
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
michaelp
1 New Member
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
Wojciech Jankun
1 New Member
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
3639
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
1690
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
1833
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
4191
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
271
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
7159
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
1625
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
2029
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
1711
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
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.