views:

92

answers:

1

Probably a stupid simple question but here goes. If I have a winform app and on the Validating_Event for a container control I call ValidateChildren().

I am assumming I need a Validate_Event for each child control that I want validated, correct? I know I need the control to have Causes Validation = True but I would still need to put my desired validation for that control somewhere and I am asking, is that control's Validating_Event the correct location?

This seems bulky...I'll have 20 Validating_Events in a given Form. Is that "normal"?

+1  A: 

Is it not abnormal, when you have 20 different rules for 20 controls. Lots of things you can do to DRY this out. If rules are the same for several controls, give those controls the same Validating event handler. If you have just a few rules, you could create your own control class by deriving from the base and bake-in the rule by overriding OnValidating. Or you could override the form's ValidatingChildren method and validate everything in one method.

Hans Passant