2

I'm developing a Word 2010 add in using Visual Studio 2010, and C#.

  • I've created a simple form, with two textboxes, and an Ok button.

  • The Ok button's Causes validation property is set to true.

  • Both textboxes CausesValidation property is set to false, and their Validating and Validated properties are set. This is so that they are only validated when the Ok button is clicked, and not when focus is changed.

If the form code is defined within the Word add in, the validating and validated events run as expected - when the Ok button is clicked. I wanted to make the form reusable, so I moved the form into a separate class library. The form largely works as expected but the validating and validated events never run with the above configuration.

Does anybody know why this is the case? Is it a bug?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Zarek
  • 939
  • 3
  • 13
  • 21
  • That sounds like a Winforms/UI problem more than anything. Have you tried calling your class library code from a straightforward Windows app? That way, you could at least figure out if the problem comes from your class library or from VSTO. – Mathias Oct 16 '10 at 16:12
  • Hi. I've now recreated a *really simple* situation: Created a class library with one form with one textbox, and one button. The button causesvalidation is set to true, and the textbox causesvalidation set to false. I've created another forms project, and added an inherited form to it. The form loads, but the textbox validating and validated events never fire (unless I set causes validation on the textbox to true, then the validating event fires when I click the button). – Zarek Oct 29 '10 at 13:04
  • It seems that I can get things working if I set the AutoValidate property of the base form to Disable, and set the CausesValidation property on the textbox to true, and call the this.ValidateChildren() method in the button click!! – Zarek Oct 29 '10 at 13:17

1 Answers1

2

It seems that you can get things working if you:

1) Set the AutoValidate property of the base form to Disable.

2) Set the CausesValidation property on the textbox to true.

3) Call the this.ValidateChildren() method in the button click.

Zarek
  • 939
  • 3
  • 13
  • 21