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

Show Modal, then Again

P: n/a
Hello Everyone,

VB.Net 2003

I would like to open a form (Form2) modally from Form1, then from Form2
display Form3 modally. It seems that once I open that third form and then
close it, the second form also closes. How can I prevent that from
happening?

I am thinking that I have to create a "Modal Helper" that will open the
desired form modally, wait for it to close and then return a result to the
caller. Am I on the right track?
TIA
Jan 24 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
"AMDRIT" <am****@hotmail.com> schrieb
Hello Everyone,

VB.Net 2003

I would like to open a form (Form2) modally from Form1, then from
Form2 display Form3 modally. It seems that once I open that third
form and then close it, the second form also closes. How can I
prevent that from happening?

Did you set the Dialogresult property of the Button in which's Click event
you show Form3?
Armin

Jan 24 '06 #2

P: n/a
I manually set the dialogresult of each form, however; I fail to see how
setting the value (which is Cancel by default) would terminated the modal
dialog of the previous form.
Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdOk.Click
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub

Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdCancel.Click
Me.DialogResult = DialogResult.Cancel
Me.Close()
End Sub


"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"AMDRIT" <am****@hotmail.com> schrieb
Hello Everyone,

VB.Net 2003

I would like to open a form (Form2) modally from Form1, then from
Form2 display Form3 modally. It seems that once I open that third
form and then close it, the second form also closes. How can I
prevent that from happening?

Did you set the Dialogresult property of the Button in which's Click event
you show Form3?
Armin

Jan 24 '06 #3

P: n/a
>From the docs for DialogResult (emphasis mine):

The dialog result of a form is the value that is returned from the form
when it is displayed as a modal dialog.

Note this part:

If the form is displayed as a dialog box, setting this property with a
value from the DialogResult enumeration sets the value of the dialog
result for the form, hides the modal dialog, and returns control to the
calling form.

Jan 24 '06 #4

P: n/a
I removed all the logic for setting the dialog result, now the button clicks
(Ok, and Cancel) now just call Me.Close(). The behavior is the same.

The first form is a mdi child of an mdi parent, i wonder if this makes a
difference. MDI Parent opens mdi child (A listview of data), from there, I
open the details view (Form2) modally, and finally one property requires yet
another form to capture the data so I open that modally.

I wonder if the mdi child is the issue?
"Chris Dunaway" <du******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
From the docs for DialogResult (emphasis mine):


The dialog result of a form is the value that is returned from the form
when it is displayed as a modal dialog.

Note this part:

If the form is displayed as a dialog box, setting this property with a
value from the DialogResult enumeration sets the value of the dialog
result for the form, hides the modal dialog, and returns control to the
calling form.

Jan 24 '06 #5

P: n/a
"AMDRIT" <am****@hotmail.com> schrieb
I manually set the dialogresult of each form, however; I fail to see
how setting the value (which is Cancel by default) would terminated
the modal dialog of the previous form.
Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdOk.Click
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub

Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdCancel.Click
Me.DialogResult = DialogResult.Cancel
Me.Close()
End Sub


I don't see where you show another form in one of these events handlers.
Armin
Jan 24 '06 #6

P: n/a
I was illustrating what I was doing on form close in response to your post.

Here is what I am doing:
open frmMain
open frmList as MDIChild
modally open frmListEdit
modally open frmMoreDetail

Public Class frmMain 'Set as MDI Container

Private Sub cmdList_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdList.Click
dim f as frmList
f = new frmList
f.mdiparent = me
addhandler f.closed, addressof frmList_Closed
End Sub

Private sub frmList_Closed(ByVal sender As Object, ByVal e As
System.EventArgs)
dim f as frmList
f= ctype(sender, frmList)
trace.writeline("List closed")
f.dispose
End Sub

End Class

Public Class frmList

Private Sub cmdEdit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEdit.Click
dim f as frmListEdit
f = new frmListEdit
f.showdialog(me)
trace.write("List Edit Closed")
f.dispose()
End Sub

End Class

Public Class frmListEdit

Private Sub cmdMoreDetail_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdMoreDetail.Click
dim f as frmMoreDetail
f = new frmMoreDetail
f.showdialog(me)
trace.write("More Detail Closed")
f.dispose()
End Sub

Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdClose.Click
me.close()
End Sub

End Class

Public Class frmMoreDetail

Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdClose.Click
me.close()
End Sub

End Class
"Armin Zingler" <az*******@freenet.de> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
"AMDRIT" <am****@hotmail.com> schrieb
I manually set the dialogresult of each form, however; I fail to see
how setting the value (which is Cancel by default) would terminated
the modal dialog of the previous form.
Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdOk.Click
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub

Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdCancel.Click
Me.DialogResult = DialogResult.Cancel
Me.Close()
End Sub


I don't see where you show another form in one of these events handlers.
Armin

Jan 24 '06 #7

P: n/a

What's the value of the Dialogresult property of frmList.cmdEdit and
frmListEdit.cmdMoreDetail?
Armin

Jan 24 '06 #8

P: n/a
Since, I didn't set a value in the code i provided, the result would be
cancel. I still fail to see how the result has anything to do with my
issue.

The issue is, when I open a form modally from a form that was open modally
and then close that form the original modal form is also closed. I do not
want the original modal form to close until the user has completed using it.

My work around, as cheap as it is, so far: Place a flag on the original
modal form, and in the closing event check set e.cancel to the flag, and
then toggle the flag off. Each time before opening a new form modally from
the original modal form I set the flag to true.

Just seems wrong to have to manage a flag when nothing asked the form to
close to begin with, and yet I need to continue to complete the task at
hand.
"Armin Zingler" <az*******@freenet.de> wrote in message
news:ux**************@TK2MSFTNGP15.phx.gbl...

What's the value of the Dialogresult property of frmList.cmdEdit and
frmListEdit.cmdMoreDetail?
Armin

Jan 24 '06 #9

P: n/a
"AMDRIT" <am****@hotmail.com> schrieb
Since, I didn't set a value in the code i provided, the result would
be cancel. I still fail to see how the result has anything to do
with my issue.


You didn't answer my question. Maybe you set the Dialogresult value in the
designer? If the Dialogresult property of frmList.cmdEdit or
frmListEdit.cmdMoreDetail has been set in the designer, the Form would be
closed after the modal Form has been shown. This would explain the problem.

For example, in cmdEdit_Click, you show frmListEdit. After frmListEdit has
been closed, the instance of frmList will be closed, too. That's what you
don't want, and that's why I ask what the value of the Dialogresult property
of frmList.cmdEdit and frmListEdit.cmdMoreDetail is.
Armin

Jan 24 '06 #10

P: n/a
I now understand what you were asking me. I didn't realize the the
commandbuttons had a dialogresult property on them, the buttons on the last
form (frmMoreDetail) had been set to cancel.

Thank you for your patience.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:e8**************@TK2MSFTNGP09.phx.gbl...
"AMDRIT" <am****@hotmail.com> schrieb
Since, I didn't set a value in the code i provided, the result would
be cancel. I still fail to see how the result has anything to do
with my issue.


You didn't answer my question. Maybe you set the Dialogresult value in the
designer? If the Dialogresult property of frmList.cmdEdit or
frmListEdit.cmdMoreDetail has been set in the designer, the Form would be
closed after the modal Form has been shown. This would explain the
problem.

For example, in cmdEdit_Click, you show frmListEdit. After frmListEdit has
been closed, the instance of frmList will be closed, too. That's what you
don't want, and that's why I ask what the value of the Dialogresult
property of frmList.cmdEdit and frmListEdit.cmdMoreDetail is.
Armin

Jan 24 '06 #11

P: n/a
"AMDRIT" <am****@hotmail.com> schrieb
I now understand what you were asking me. I didn't realize the the
commandbuttons had a dialogresult property on them, the buttons on the last
form (frmMoreDetail) had been set to cancel.

Thank you for your patience.

But the last form isn't the problem. :-) The problem is that frmList and
frmListEdit are closed unintentionally, isn't it? Thus, I /still/ wonder
what's the value of the dialogresult property of frmList.cmdEdit and
frmListEdit.cmdMoreDetail. These are the buttons that show a modal form.
Please select each of these two buttons in the designer and have a look at
their dialogresult property. What is the value? Maybe you accidently set
them when copying buttons in the designer.

Again, for example, if you set cmdMoreDetail.Dialogresult (in frmListEdit)
to Dialogresult.Ok (in the designer), clicking the button means:

1. The Dialogresult property of the form (frmListEdit) is set to
Dialogresult.Ok. This is done automaticall because this is the value of the
buttons's Dialogresult property.

2. cmdMoreDetail_Click is raised. In the event handler, you show and close
frmMoreDetail.

3. frmListEdit ist closed! This is an automatic mechanism: If the Form's
Dialogresult property value has been set to a value different from
Dialogresult.None - this happened in step 1 - the Form is closed
automatically. In this case you return to frmList because showdialog, within
cmdEdit_Click, returns.
Armin

Jan 24 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.