Solved

Continue event processing after prompting within the Validating event handler (.NET)

Posted on 2006-10-19
3
176 Views
Last Modified: 2010-04-16
I have many controls visible simultaneously on my .NET 2.0 Windows Form. One of them is an "editor," and when the user tries to leave that control by clicking on another control, I want to prompt the user to save their editing session, with a "Yes/No/Cancel" prompt. If the user clicks "Yes" or "No", then (after saving if they clicked "Yes"), the original click event should be processed. if they click "Cancel," the user should remain in the original "editor" control.

To cancel, I just set the Validating event handler's CancelEventArgs argument's Cancel property to true (i.e., e.Cancel = true;).

However, displaying the MessageBox prompt in the Validating event interferes with the processing of the original event. How can I continue processing the original event when the user clicks "Yes" or "No"?
0
Comment
Question by:AlphaGuys
3 Comments
 

Author Comment

by:AlphaGuys
ID: 17821481
I found my own answer somewhere else. By using a new thread in the Validating event, the application can prompt the user and handle the responses without interfering with the event processing of the original, main thread. Kinda like this:


   DialogResult m_dr;

   private void myControl_Validating(object sender, CancelEventArgs e)
   {

            System.Threading.Thread t = new System.Threading.Thread(askUser);
            t.Start();
            t.Join();

            switch (m_dr)
            {
                 <handle user's response here>
            }
   }

   private void askUser()
   {
         m_dr = MessageBox.Show("Do you want to save your changes?", "", MessageBoxButtons.YesNoCancel);
   }
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17849419
Closed, 500 points refunded.
DarthMod
Community Support Moderator
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question