Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This is about my first experience with programming Arduino.
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 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 …

808 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