• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1334
  • Last Modified:

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?
0
u2envy1
Asked:
u2envy1
  • 2
  • 2
1 Solution
 
anarki_jimbelCommented:
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
 
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 ?
0
 
anarki_jimbelCommented:
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
 
u2envy1Author Commented:
Thx
I have code in the toolStripButton1_Click event that must not execute if a Validation occurs.
How can this be done ?
0
 
ketelhutCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now