[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ToolStripButton .Net 2.0 CausesValidation Property and Validating...

Posted on 2008-11-13
5
Medium Priority
?
1,311 Views
Last Modified: 2012-06-21
I have a Windows Forms application using VS 2005.  When running the App I want to have CausesValidation Property and the Validating Event to be available for me to use when I move from a TextBox to a ToolStripButton.  The Problem is that the ToolStripButton does not support CausesValidation Property or the Validating Event (ToolStripTextBox does suport Validation via the parent class ToolStripControlHost also ToolStrip does via the parent class Control) But ToolStripButton does not.

How can I have my TextBox validate when the user move from the TextBox to the the ToolStripButton?
0
Comment
Question by:u2envy1
  • 2
  • 2
5 Comments
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 22982115
Honestly, I probably don't understand the problem.

If you move from a textbox to a button - what do you wan't to validate? If you want to validate the textbox all you need is to add validating event handler. For that you select the textbox in designer, go to Properties tab, click "lightening" button and select Validating event. Double click it. Put any code there, e.g. MesageBox.Show("Hello") just to try. Now, when you leave the textbox the Validating event happens and handler is executed.

Or pls clarify the problem.
0
 

Author Comment

by:u2envy1
ID: 22982354
Let me clarify....
I have a validate event on a textbox. If you tab away from the textbox the validation fires. If you mouse click on a button that is placed on the ToolStrip the validation is not fired. The ToolStripButton does not have a causes validation property. Any work around to fire the validation on mouse click for the ToolStripButton ?
0
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 1500 total points
ID: 22988048
Honestly it was a surprise for me. I tried before with a textbox on the same toolstrip - and validation worked. But you are right - if we have a normal textbox and click a button on a toolstrip validation event is not fired.

Now I can see the only way: to call the validation event handler from the button click event handler. See the snippet.
        // validating event handler for a textbox
        private void textBox1_Validating(object sender, CancelEventArgs e)
        {
            MessageBox.Show("Val2");
        }
 
        // toolstrip button click event handler
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            // call texbox validation manually
            textBox1_Validating(textBox1, new CancelEventArgs());
        }

Open in new window

0
 

Author Comment

by:u2envy1
ID: 22992392
Thx
I have code in the toolStripButton1_Click event that must not execute if a Validation occurs.
How can this be done ?
0
 

Expert Comment

by:ketelhut
ID: 32818007
Instead of explizit calling the validation event of the control, it is better to move the focus somewhere. The focus isn't moved from your control to validate, while clicking the toolstrip. That's the reason why the event is not firing. Just move it to a label, and the validate will fire.

Private Sub TSB_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TSB_Speichern.Click
        Label1.Focus()
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

872 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