ToolStripButton .Net 2.0 CausesValidation Property and Validating...

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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

anarki_jimbelSenior DeveloperCommented:
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.
u2envy1Author Commented:
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 ?
anarki_jimbelSenior DeveloperCommented:
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)
        // 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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
u2envy1Author Commented:
I have code in the toolStripButton1_Click event that must not execute if a Validation occurs.
How can this be done ?
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.