Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

How to validate all controls in Win forms?


I have a form which has a text field with a error provider and validation code in the validating and validated events.

If I tab into the textbox and then tab out, the control gets validated (I am checking against empty) but if I click on my O.K. button which has the causesvalidation property set to true, It doesn't validate the control.

Is this a know winforms bug and if not, how do I get potentially every control on my form to validate.

I am using C# and .Net 1.1

Friday, April 8, 2005

This is not a bug. The control never received focus so the validating event is not called.

If you take a look at this site:

you'll see some validation controls that Michael Weinhardt wrote that will do what you want. There is also a 3 part write up on MSDN. Do a search on Michael's name.

Hope that helps.

Ron Green
Saturday, April 9, 2005

PS You can do this without the controls listed above but you'll have to duplicate your validation code in the button_click event handler.

Ron Green
Saturday, April 9, 2005

This is exactly why many of us roll our own validation instead of using the built-in stuff. This is one of my biggest disappointments with .NET.

Saturday, April 9, 2005

Thanks Guys.

I will take a look at Ghengis.

Monday, April 11, 2005

*  Recent Topics

*  Fog Creek Home