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?
6 32684
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 ...
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: - private void button1_Click(object sender, EventArgs e)
-
{
-
(new Form2()).ShowDialog();
-
}
Form2: - private void button1_Click(object sender, EventArgs e)
-
{
-
(new Form3()).ShowDialog();
-
}
Form3: - 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
No dialog result on the second form.
I have this button click handler on the Main Form: -
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" -
private void BTN_SEARCHBRAIN_Click(object sender, EventArgs e)
-
{
-
(new AutoSearchBrains()).ShowDialog();
-
}
-
and then on AutoSearchBrain Form (OK and Canel Buttons) -
#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?
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.
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 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
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |