Winform and ValidateChildren()
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 开发者_如何学CValidateChildren()
.
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"?
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.
精彩评论