This is a migrated thread and some comments may be shown as answers.

Iterate through timepickers

2 Answers 51 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 02 Oct 2014, 06:28 PM
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 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 03 Oct 2014, 08:08 AM
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.
 
0
Chris
Top achievements
Rank 1
answered on 04 Oct 2014, 07:14 PM
Excellent. Thank you.
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Chris
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Chris
Top achievements
Rank 1
Share this question
or