By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,426 Members | 1,729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,426 IT Pros & Developers. It's quick & easy.

Using multiple modal dialogs in a Windows app

P: n/a
Hello,

I have a Windows form that opens a modal dialog window. From there I
can open yet another modal dialog window so I can grab some info to
pass back to the first dialog. Both need to be modal and are launched
like this:
>From my main Windows form:
if (formName1.ShowDialog( this ) == DialogResult.OK)
......
>From formName1:
if (formName2.ShowDialog( this ) == DialogResult.OK)
......

I have OK buttons on both modal forms that return a DialogResult of OK
and then they do formName.Close(). They both also have a Cancel
button with simply a formName.Close().

My problem is when I close the second dialog window via either a
Cancel or OK, the first one closes with it, and I would like for the
first to stay open :)

Does anyone have any ideas?

Mike

Sep 6 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 6 Sep., 04:42, Mike <mccar...@hotmail.comwrote:
Hello,

I have a Windows form that opens a modal dialog window. From there I
can open yet another modal dialog window so I can grab some info to
pass back to the first dialog. Both need to be modal and are launched
like this:
From my main Windows form:

if (formName1.ShowDialog( this ) == DialogResult.OK)
......
From formName1:

if (formName2.ShowDialog( this ) == DialogResult.OK)
......

I have OK buttons on both modal forms that return a DialogResult of OK
and then they do formName.Close(). They both also have a Cancel
button with simply a formName.Close().

My problem is when I close the second dialog window via either a
Cancel or OK, the first one closes with it, and I would like for the
first to stay open :)

Does anyone have any ideas?

Mike
I tried reproducing the problem you describe, but it seems to work
fine for me.
Creating 3 windows, each with a button with its DialogResult-Property
set to OK, the first one calling ShowDialog on the second and the
second on the third, behave exactly as expected.
Could you post a short program that still causes the unexpected
behavior?
As a sidenote: You don't actually have to call Close on the form
within a button's click-event if the button has a DialogResult
associated with it, the form will close automatically after the button
is pressed.

Kevin Wienhold

Sep 6 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.