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*********@the rmo.com 5 3423
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
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.microsof t.com> wrote in message
news:db******** ******@cpmsftng xa10.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
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
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.ShowDialo g();
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 FileNotFoundExc eption("Could not save to file XYZ....");
}
catch(FileNotFo undException 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.microsof t.com> wrote in message
news:QR******** ******@cpmsftng xa10.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
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*********@the rmo.com>" <<Remove this before reply> wrote in
message news:uB******** ******@TK2MSFTN GP11.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.ShowDialo g();
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 FileNotFoundExc eption("Could not save to file XYZ....");
}
catch(FileNotFo undException 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.microsof t.com> wrote in message news:QR******** ******@cpmsftng xa10.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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 Recordset
object a following run-time error occurs: Unhandled exception in
testdb.exe(KERNEL32.DLL):
0xE06D7363: Microsoft C++ Exception.
I created my database by 3 SQL commands:
|
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 dialog like this:
if (formOptions.ShowDialog(this) == DialogResult.OK)
When the user clicks on "Save" in the form I do the
validation and regardless of success or failure in the
|
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 the code is 100% managed. The
exception is not thrown if the dialog was modal (opened with ShowDialog()) or
if the selection is made from, say, a ListBox.
I have included a simple example below.
I am using C#.NET 2003, Standard Edition.
|
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 instantiating a particular class in
my project but the dialog doesn't tell me what code in the class is causing
the problem (and it a large class).
How can I get the IDE to take me to the offending line of code?
If I put this line in my...
|
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 involved extending explorer by creating a
context-menu extension and allow certain actions to be performed on
certain files. I was able to get that up and running through much
searching on google, but the overall goal of the projects seems like it...
| |
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 to the vb, but I'm thinking
that it may likely be the vb.
I'm attempting to open a java modal dialog box from a parent window. I have
most of the dialog box working with one problem. The dialog box opens fine
with the code below associated with...
|
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?
|
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();
Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name);
|
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 exception occurs
pointing to FileSaveDialog1.ShowDialog(). The exception also
indicates some problem with system.drawing.dll.
The exception text is:
"Attempted to read or write protected memory. This is often an
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |