473,398 Members | 2,212 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,398 software developers and data experts.

closing Modal Form inside form

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 an OK button press. See
Example:

private void add_Click(object sender, EventArgs e)
{
// Do some work...

if (itemcnt == 0)
{
this.DialogResult = DialogResult.Cancel;
// Close current form and return.
}
}

May 9 '07 #1
3 2027
Phil,

You can just call the Close method on your form. You are specifying the
value of the DialogResult property beforehand, and this is what will be
returned from the call to ShowModal.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Phil" <ph****@sbcglobal.netwrote in message
news:66**********************************@microsof t.com...
>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 an OK button press.
See
Example:

private void add_Click(object sender, EventArgs e)
{
// Do some work...

if (itemcnt == 0)
{
this.DialogResult = DialogResult.Cancel;
// Close current form and return.
}
}

May 9 '07 #2
When I do this from inside my add_Click() function , I get an error:
Cannot access a disposed object.
Object name: 'ConflictList'.

The error is shown at the semicolon after I call ShowDialog(); i.e.

ConflictList dlg = new ConflictList();
dlg.ShowDialog();<- Right here

Any ideas?

Phil
"Nicholas Paldino [.NET/C# MVP]" wrote:
Phil,

You can just call the Close method on your form. You are specifying the
value of the DialogResult property beforehand, and this is what will be
returned from the call to ShowModal.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Phil" <ph****@sbcglobal.netwrote in message
news:66**********************************@microsof t.com...
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 an OK button press.
See
Example:

private void add_Click(object sender, EventArgs e)
{
// Do some work...

if (itemcnt == 0)
{
this.DialogResult = DialogResult.Cancel;
// Close current form and return.
}
}


May 9 '07 #3
Hello,

Are you sure you don't have any other references of ConflictList in
dlg?

The solution that Nicholas suggested is the way to that.
Just set the DialogResult the value you want, and call this.Close().

The error you mentioned doesn't seem to have anything with the closure
of the form.

Hope this helps.

May 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide...
2
by: Asad | last post by:
I have a form on a page that has several textareas, and textboxes inside a table (so the table containing the textboxes is also inside the FORM tag). I want to replace the textareas with simple...
2
by: developer | last post by:
I have a form with a menu on the top. This menu show another form. I want to open this second form maximized inside the parent form just below the menu of the parent form. (Like Microsoft...
4
by: anders | last post by:
I have a 'solution' with a Webservice, Business layer and a data layer. In the Business layer I've added a form that need to be started on the server(this site has full rights, runs with Local...
1
by: **Developer** | last post by:
When I get a closing event in a MID Child form I don't know if the child form is closing or the main form is closing. Is there a way to tell? Thank
0
by: Jake Wiley | last post by:
I need to enable a menu item on a parent based on the closing of a child form. I need help in general on how to let the parent know the child has closed. Here are the basic steps I've done: Menu...
7
by: Boki | last post by:
Hi All, When we delacre a main, why we dlacre it inside form? Why not outside of form? If form contains main(), why not every form contains a main()... Best regards, Boki.
12
by: djmauro | last post by:
as title says. I cant find a way to do this. if i use form1.show and click on a button. it opens that form, but as soon as i click again it just reopens it and closes previously opened form. So is...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.