473,239 Members | 1,584 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,239 software developers and data experts.

How to Keep Dialog Open When Exception Occurs

Hi,

I need some dialog handling help, I must be missing something obvious here
but I can't figure out the solution to the following problem...

Simple Win Forms app that has button on the form. The click event handler
for the button creates another dialog (as a form object) and calls it's
ShowDialog method to dsiplay it modally. The secondary dialog then appears
that has OK and Cancel buttons and the user can interact as expected. Now
when the user chooses OK some settings need to be recorded to disk, so I
trap the possible exceptions and dutifully show a MessageBox when needed
informing them what went wrong. The problem is that once the exception has
been handled and the error MessageBox dimissed, the secondary dialog also
disappears. I want it to stay open until they can either store everything
correctly or choose Cancel. Basically, I need to abort the OK click event
handler prematurely so the secondary dialog stays open. How do I do that?

TIA,

--
John C. Bowman
Software Engineer
Thermo Electron Scientific Instruments Div.
<Remove this before reply> jo*********@thermo.com
Nov 16 '05 #1
5 3401
hi Tia
What you have here is a message box. For MessageBox clicking
ok or cancel trigger the close event ( so it will be closed once you click
ok or cancel no matter if form one has error or not ) . What you can do is
that in your event handler "that exist in form one "you reopen the message
box once you done handling the error. However, this is not a neat solution.
A good solution would be to implement an error provider object
on form one, and enable validation for all the controls where the user can
enter an incorrect date. This way you grantee that the use cannot leave a
control on form one unless he/ she has entered a valid input of an
acceptable range.
hope that helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2
Mohamed,

Thanks for the response. I know the MessageBox error dialog will go away
because it is called in the "OK" button's click event and is modal. However,
it's the second form (the one containing the "OK" button) that is a dialog
that I want to leave open until no errors writing to disk occur. It really
has nothing to do w/ what the user enters in the form, as the user is never
actually allowed to "enter" anything, just selections. These choices need to
be saved to disk someplace. If anything goes wrong during the write (aka an
exception), then leave the dialog open after the error MessageBox is
dismissed.

John

"Mohamoss" <mo************@egdsc.microsoft.com> wrote in message
news:db**************@cpmsftngxa10.phx.gbl...
hi Tia
What you have here is a message box. For MessageBox clicking
ok or cancel trigger the close event ( so it will be closed once you click
ok or cancel no matter if form one has error or not ) . What you can do is
that in your event handler "that exist in form one "you reopen the message
box once you done handling the error. However, this is not a neat solution. A good solution would be to implement an error provider object
on form one, and enable validation for all the controls where the user can
enter an incorrect date. This way you grantee that the use cannot leave a
control on form one unless he/ she has entered a valid input of an
acceptable range.
hope that helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #3
hi
would you post a Snap of the code where the problem happen i.e. the
exception is raised . ......................
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #4
Mohamed,

Thanks, here's the example code.... It's incredibly simple.

Form1 has a button, it's click event has the following code:

CDlg MyDlg = new CDlg();

MyDlg.ShowDialog();
CDlg is a simple windows forms dialog containing 2 buttons (OK and Cancel),
but simulates an options dialog where several settings need to be choosen by
the user. When the user chooses the "OK" button on this dialog, some
error(s) (aka exceptions) might occur while the user's settings are being
saved to disk. The CDlg form's OK button's click event has code like the
following...

try

{

//Simulate a disk error of some kind while saving the settings the user has
choosen on this dialog

throw new FileNotFoundException("Could not save to file XYZ....");

}

catch(FileNotFoundException eFileNotFound)

{

MessageBox.Show(eFileNotFound.Message);

}
Now, when the user responds to the MessageBox by pressing it's OK button, it
goes away, this is fine. But so does MyDlg, which is NOT what I want. I
want MyDlg to stay right where it is. How do I do this?

John
"Mohamoss" <mo************@egdsc.microsoft.com> wrote in message
news:QR**************@cpmsftngxa10.phx.gbl...
hi
would you post a Snap of the code where the problem happen i.e. the
exception is raised . ......................
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #5
Hi,

I found the "trick". I needed to set the DialogResult for the 2nd form to
None in it's Ok button's event handler when an error occurs after the
MessageBox. This causes the ShowDialog method to not exit and the dialog
stays's open.

John

"John Bowman jo*********@thermo.com>" <<Remove this before reply> wrote in
message news:uB**************@TK2MSFTNGP11.phx.gbl...
Mohamed,

Thanks, here's the example code.... It's incredibly simple.

Form1 has a button, it's click event has the following code:

CDlg MyDlg = new CDlg();

MyDlg.ShowDialog();
CDlg is a simple windows forms dialog containing 2 buttons (OK and Cancel), but simulates an options dialog where several settings need to be choosen by the user. When the user chooses the "OK" button on this dialog, some
error(s) (aka exceptions) might occur while the user's settings are being
saved to disk. The CDlg form's OK button's click event has code like the
following...

try

{

//Simulate a disk error of some kind while saving the settings the user has choosen on this dialog

throw new FileNotFoundException("Could not save to file XYZ....");

}

catch(FileNotFoundException eFileNotFound)

{

MessageBox.Show(eFileNotFound.Message);

}
Now, when the user responds to the MessageBox by pressing it's OK button, it goes away, this is fine. But so does MyDlg, which is NOT what I want. I
want MyDlg to stay right where it is. How do I do this?

John
"Mohamoss" <mo************@egdsc.microsoft.com> wrote in message
news:QR**************@cpmsftngxa10.phx.gbl...
hi
would you post a Snap of the code where the problem happen i.e. the
exception is raised . ......................
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC


Nov 16 '05 #6

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

Similar topics

1
by: Mad Hot dog | last post by:
Hello group! I use MS Visual C++ 6.0, ADO, MS SQL Server 2000. When I attempt to open my database I meet with a following problem: when I try to get a bookmark of the current record in a...
2
by: Ron Rohrssen | last post by:
I'm trying to use the ErrorProvider in order to validate my form. This is working well except that in the event of a failure on my modal dialog, I'd like to keep the dialog open. I open the...
3
by: Andrew | last post by:
I get a Null Reference Exception if I close a non-modal dialog (that is, a form opened with Show()) when a selection is made from a ComboBox. The error message refers to Unsafe Native Methods, but...
6
by: Steve Long | last post by:
Help, I'm running VS.NET 2003 and when I try to start my application, I get the "unhandled exception" dialog instead of the IDE highlighting the offending line of code. The problem appears to be...
1
by: kmslick | last post by:
Hello all. Not sure which group this problem best relates to, so I'm posting to both with a follow up. I started learning C# and .NET last august for a project for my employer. The project...
3
by: Jeff | last post by:
I'm hoping that someone can help me. I know little javascript and only need a very small amount in a visual web 2005 application using vb. I'm not sure whether my problem is related to the java or...
7
by: mail747097 | last post by:
I would like to keep IIS alive on my web site and prevent Application_End from occuring in global.asax. Any ideas?
7
by: Peter | last post by:
ASP.NET 2.0 I am trying to open a Word document and Excel document from a dialog web page, what's the best way to do that? I have tried the following: Response.Clear();...
6
by: Scott Gravenhorst | last post by:
Windows XP SP3 My application is set to open a SaveFile dialog when an exit is requested. When I click the app's close button, the save dialog opens, but when I click to change the folder, the...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.