Iterate through timepickers

3 posts, 0 answers
  1. Chris
    Chris avatar
    15 posts
    Member since:
    Aug 2012

    Posted 02 Oct 2014 Link to this post

    I have a whole bunch of timepcikers on a form. I need to have a button on the form to set all times to 12:00 AM. It is a rest for the user. I wanted to do something like this:


    foreach(Control c in this.Controls)
    {
    if(c is radTimePicker)
    {
    // set time here ;]
    }
    }

    I'm not sure what I should use for "Control" and "this.Controls" I'm guessing radTimePicker is correct.
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 03 Oct 2014 Link to this post

    Hi Chris,

    Thank you for writing.

    If all the controls on your form are on the same level, you can use the following code snippet to iterate them and set the time of the time pickers:
    foreach (Control c in this.Controls)
    {
        if (c is RadTimePicker)
        {
            RadTimePicker timePicker = (RadTimePicker)c;
            timePicker.Value = new DateTime(1, 1, 1, 10, 10, 10);
            // set time here ;]
        }
    }

    If the controls are on different levels, you can iterate them recursively.

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Chris
    Chris avatar
    15 posts
    Member since:
    Aug 2012

    Posted 04 Oct 2014 in reply to Stefan Link to this post

    Excellent. Thank you.
Back to Top