开发者

Validating/ed events not firing in class library windows form

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 wi开发者_Go百科th the above configuration.

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜