Solved

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

Posted on 2006-10-19
3
174 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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 …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now