Solved

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

Posted on 2006-10-19
3
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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…
Simple Linear Regression

695 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