views:

21

answers:

1

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.

A: 

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.

YWE