ValidateChildren on a tab control

C

Caroline M

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.
 
O

Otis Mukinfus

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
 
C

Caroline M

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
 
O

Otis Mukinfus

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.


No these are data-input type controls, not used for navigation.


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
 

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