Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 83
oracle query help 18 99
detecting  the added row index in a datagridview 3 54
Basic Java Case or If-Else statement... 3 43
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A short article about problems I had with the new location API and permissions in Marshmallow
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

930 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

16 Experts available now in Live!

Get 1:1 Help Now