开发者

WinForms: Cannot get ValidateChildren to raise Validating event of a child control

In a Windows Form application I have a Form with a UserControl that contains a child control. I have an event handler for the child control's Validating event. On the parent UserControl I call the ValidateChildren() method. But the event handler for the child control's Validating event does not run. The CausesValidation property is set to true on both the parent UserControl and the child control. Is there any reason why the Validating event handler would not run?

The child control is a custom control derived from Panel. It contains two RadioButton开发者_运维知识库 controls, both of which have their CausesValidation property set to true.


I think I figured it out. The control was not raising the Validating event because it was not selectable. A Panel control is not by default selectable nor are controls derived from Panel (See link text). So in the UserControl's constructor I called SetStyle(ControlStyles.Selectable, true);. Now it raises the Validating event.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜