By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,769 Members | 1,616 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,769 IT Pros & Developers. It's quick & easy.

ValidateChildren on a tab control

P: n/a
Hi,

I'm very new to windows forms and C# so this is my first post in this
group :-) I have a very simple forms app with a tab control containing
two tabs. Its related to football and one tab relates to players and
the other tab to teams. I'm using the ErrorProvider component to
display error information which I set in the Validating handlers for
the controls that need validating.

I set the form to AutoValidate.EnableAllowFocusChange and then in my
button that I want the validation performed in (I have a save button
in each tab) I was hoping I could use the ValidateChildren method to
invoke all of those handlers. The problem is that ValidateChildren
would seem to only apply to the form as a whole and I want to treat
the controls on each tab separately. Of course what is happening is
that if the user enters some data in the player tab for example and
tries to save it, the validation events for the teams tab also kick in
and if those controls are empty then the form as a whole is invalid.

The tab control doesn't seem to have a ValidateChildren function and I
can't seem to find any way of grouping them. According to the docs I
should be able to call the method on any class that is a
ContainerControl but I dont know of any classes that are derived from
that one!

Any help much appreciated,

Caroline M.

Jan 31 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 31 Jan 2007 01:50:50 -0800, "Caroline M"
<ca******************@googlemail.comwrote:
>Hi,

I'm very new to windows forms and C# so this is my first post in this
group :-) I have a very simple forms app with a tab control containing
two tabs. Its related to football and one tab relates to players and
the other tab to teams. I'm using the ErrorProvider component to
display error information which I set in the Validating handlers for
the controls that need validating.

I set the form to AutoValidate.EnableAllowFocusChange and then in my
button that I want the validation performed in (I have a save button
in each tab) I was hoping I could use the ValidateChildren method to
invoke all of those handlers. The problem is that ValidateChildren
would seem to only apply to the form as a whole and I want to treat
the controls on each tab separately. Of course what is happening is
that if the user enters some data in the player tab for example and
tries to save it, the validation events for the teams tab also kick in
and if those controls are empty then the form as a whole is invalid.

The tab control doesn't seem to have a ValidateChildren function and I
can't seem to find any way of grouping them. According to the docs I
should be able to call the method on any class that is a
ContainerControl but I dont know of any classes that are derived from
that one!

Any help much appreciated,

Caroline M.
Good morning Caroline,

Have you tried setting the Tab's CausesValidation property to false?

When using validation you can set controls that way to prevent them from
validating data on the form. One example of that would be to set a Cancel
button's CausesValidation property to false, because if the user cancels a form
there is normally no validation required. I would think in your case the same
is true of the tab tabs you are using. I can't think of why you would need to
validate on the selection of tabs.

I think a good rule to follow when using the validation controls is that if a
control is used for nothing but navigation it should not cause validation to
occur. On the other hand validation should occur when the user takes an action
that would submit the data to storage (clicking the OK button or something like
that).
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Jan 31 '07 #2

P: n/a
Have you tried setting the Tab's CausesValidation property to false?

No
is true of the tab tabs you are using. I can't think of why you would need to
validate on the selection of tabs.
I need the validation depending on the context of the tab. If the user
is on the player tab then I want to ensure that all the player-related
controls on that tab are validated. Likewise for the teams tab. But of
course if I am on the player tab, I dont care about the team controls
in that context.
I think a good rule to follow when using the validation controls is that if a
control is used for nothing but navigation it should not cause validation to
occur. On the other hand validation should occur when the user takes an action
No these are data-input type controls, not used for navigation.
Good luck with your project,
Thanks :)

Caroline

Jan 31 '07 #3

P: n/a
On 31 Jan 2007 06:35:02 -0800, "Caroline M"
<ca******************@googlemail.comwrote:
>Have you tried setting the Tab's CausesValidation property to false?

No
>is true of the tab tabs you are using. I can't think of why you would need to
validate on the selection of tabs.

I need the validation depending on the context of the tab. If the user
is on the player tab then I want to ensure that all the player-related
controls on that tab are validated. Likewise for the teams tab. But of
course if I am on the player tab, I dont care about the team controls
in that context.
>I think a good rule to follow when using the validation controls is that if a
control is used for nothing but navigation it should not cause validation to
occur. On the other hand validation should occur when the user takes an action

No these are data-input type controls, not used for navigation.
>Good luck with your project,

Thanks :)

Caroline
OK,

I think you might have misunderstood what I meant by navigation. In my mind
navigation controls are buttons and tabs. But as Dennis Miller frequently
say's, "That's just my opinion. I could be wrong.".

Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.com
http://www.arltex.com
http://www.tomchilders.com
http://www.n5ge.com
Jan 31 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.