Can't get ValidateChildren to validate

  • Thread starter Flomo Togba Kwele
  • Start date
F

Flomo Togba Kwele

I have a UserControl with 2 textboxes as its only controls. AutoValidate is set
to EnableAllowFocusChange, although I've tried EnablePreventFocusChange and
Disable with the same results. The textboxes are not databound.

I have also defined an ErrorProvider, which is set in both textbox Validating
eventhandlers when appropriate.

The 2 boxes represent a starting and ending number. The number in the second
textbox must not be less than the number in the first.

I enter a number in the first text box, tab to the second, enter a number and
then click on a toolstripbutton to begin the process. The first thing I do is
call the UserControl's ValidateChildren method. Since I have not tabbed off the
second textbox, validation on it has not occured.

In fact, the validating eventhandler for the first textbox was not fired. What
do I have to do to make the Validating eventhandlers fire?

Thanks, Flomo

--
 
L

Linda Liu [MSFT]

Hi Flomo,

Based on my understanding, you have a UserControl which contains two
TextBox. You add the UserControl and a ToolStrip on the form. When you
click a ToolStripButton in the ToolStrip, you'd like to validate the two
textboxes in the usercontrol. If I'm off base, please feel free to let me
know.

ContainerControl.AutoValidate property gests or sets a value that indicates
whether controls in this container will be AUTOMATICALLY validated when the
focus changes. If the AutoValidate property is set to a value other than
Disable, when a child control, e.g. a textbox losts focus, the Validating
event of the control is raised; otherwise, the Validating event won't be
raised, in which case, we have to call the container control's
ValidateChildren method to get the child controls validated.

Note that even if we set the UserControl's AutoValidate property to a value
other than Disable, when the textbox in the UserControl gets focused and
you click a ToolStripButton on the form, the textbox's Validating event
won't be fired, because clicking on a ToolStripButton won't require to take
the focus. In this case, I suggest that you set the UserControl's
AutoValidate property to Disable and call the ValidateChildren method of
the UserControl when you click the ToolStripButton.

You may get a complete sample on following MSDN documentation.

'ContainerControl.AutoValidate Property'
http://msdn2.microsoft.com/en-us/library/system.windows.forms.containercontr
ol.autovalidate(VS.80).aspx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
F

Flomo Togba Kwele

Thanks, Linda, the article helped.

Flomo
--


Hi Flomo,

Based on my understanding, you have a UserControl which contains two
TextBox. You add the UserControl and a ToolStrip on the form. When you
click a ToolStripButton in the ToolStrip, you'd like to validate the two
textboxes in the usercontrol. If I'm off base, please feel free to let me
know.

ContainerControl.AutoValidate property gests or sets a value that indicates
whether controls in this container will be AUTOMATICALLY validated when the
focus changes. If the AutoValidate property is set to a value other than
Disable, when a child control, e.g. a textbox losts focus, the Validating
event of the control is raised; otherwise, the Validating event won't be
raised, in which case, we have to call the container control's
ValidateChildren method to get the child controls validated.

Note that even if we set the UserControl's AutoValidate property to a value
other than Disable, when the textbox in the UserControl gets focused and
you click a ToolStripButton on the form, the textbox's Validating event
won't be fired, because clicking on a ToolStripButton won't require to take
the focus. In this case, I suggest that you set the UserControl's
AutoValidate property to Disable and call the ValidateChildren method of
the UserControl when you click the ToolStripButton.

You may get a complete sample on following MSDN documentation.

'ContainerControl.AutoValidate Property'
http://msdn2.microsoft.com/en-us/library/system.windows.forms.containercontr
ol.autovalidate(VS.80).aspx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top