locked
Is there a way to make validate children method work on all controls? RRS feed

  • Question

  • I have a form. With tabs. Every control has a validating event handler. When I call validateChildren(), however, it only validates the visible controls, those on the current tab. Is there a way to validate all controls on the form, even the ones that are not on the current tab? I know I can manually call validators, but was just wondering if there is some propert I can set somewhere to make ValidateChildren do this?
    Tuesday, September 13, 2011 3:58 PM

Answers

  • Here's a code sample that iterates through every control instance on a form, and invokes a delegate with each instance.

    Iterate through the controls on a form.

    Or, you could use this more direct approach to iterate all of the controls on a form.

    Iterate through controls 

    All controls means *all* controls, including panels, tabcontrols, pictureboxes, etc.  Anything in the form.Controls collection.

    Hope this helps.

    Rudy   =8^D

     


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    • Marked as answer by Helen Zhou Tuesday, September 27, 2011 6:06 AM
    Tuesday, September 13, 2011 5:33 PM
  • Hi mscheaf,

    To loop through all the controls on all the tabpages, you can do it like:

    foreach (TabPage tp in TabControl1.TabPages) 
    {
           foreach (Control ctl in tp.Controls) 
           {
                 //do your validateChildren here
           }
    }
    

     


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Helen Zhou Tuesday, September 27, 2011 6:06 AM
    Friday, September 16, 2011 3:24 AM

All replies

  • Here's a code sample that iterates through every control instance on a form, and invokes a delegate with each instance.

    Iterate through the controls on a form.

    Or, you could use this more direct approach to iterate all of the controls on a form.

    Iterate through controls 

    All controls means *all* controls, including panels, tabcontrols, pictureboxes, etc.  Anything in the form.Controls collection.

    Hope this helps.

    Rudy   =8^D

     


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    • Marked as answer by Helen Zhou Tuesday, September 27, 2011 6:06 AM
    Tuesday, September 13, 2011 5:33 PM
  • Hi mscheaf,

    To loop through all the controls on all the tabpages, you can do it like:

    foreach (TabPage tp in TabControl1.TabPages) 
    {
           foreach (Control ctl in tp.Controls) 
           {
                 //do your validateChildren here
           }
    }
    

     


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Helen Zhou Tuesday, September 27, 2011 6:06 AM
    Friday, September 16, 2011 3:24 AM