PC Review


Reply
Thread Tools Rate Thread

closing Modal Form inside form

 
 
=?Utf-8?B?UGhpbA==?=
Guest
Posts: n/a
 
      9th May 2007
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.
}
}

 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      9th May 2007
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]
- (E-Mail Removed)

"Phil" <(E-Mail Removed)> wrote in message
news:6679EEA7-2F7F-4B48-982B-(E-Mail Removed)...
>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.
> }
> }
>



 
Reply With Quote
 
=?Utf-8?B?UGhpbA==?=
Guest
Posts: n/a
 
      9th May 2007
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]
> - (E-Mail Removed)
>
> "Phil" <(E-Mail Removed)> wrote in message
> news:6679EEA7-2F7F-4B48-982B-(E-Mail Removed)...
> >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.
> > }
> > }
> >

>
>
>

 
Reply With Quote
 
Maverick
Guest
Posts: n/a
 
      10th May 2007
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
run an Excel file inside a modal Access form .. =?Utf-8?B?a2s=?= Microsoft Access Forms 1 9th Nov 2006 03:23 AM
(Access FIND/REPLACE ) inside a Popup/Modal form? ApexData@gmail.com Microsoft Access Form Coding 1 8th Mar 2006 09:25 AM
(FIND&REPLACE) inside a Popup/Modal Form? ApexData@gmail.com Microsoft Access Forms 0 7th Mar 2006 10:56 PM
Closing Modal Form stops Task Bar Doug Bell Microsoft Dot NET 0 24th Nov 2004 12:54 AM
Closing a modal form? Karen Microsoft Access Form Coding 2 16th Jan 2004 10:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:46 AM.