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

Setting time range for time selector

7 Answers 491 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
Auvo
Top achievements
Rank 1
Auvo asked on 25 Sep 2015, 05:53 AM

Hi,

 

How can I set the time range for time selector in RadTimePicker?

User need to select time between 06:30 - 09:00 with time range 10min

Without that range, time selector looks quite messy

 

I tried to use DisplayDateStart and -end properties but it did not help

 

FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(Telerik.Windows.Controls.RadTimePicker));
spFactory.Name = "factory";
spFactory.SetValue(Telerik.Windows.Controls.RadTimePicker.TimeIntervalProperty, new TimeSpan(0, 10, 0));
spFactory.SetValue(Telerik.Windows.Controls.RadTimePicker.DisplayDateStartProperty, new DateTime() + new TimeSpan(6, 30, 0));
spFactory.SetValue(Telerik.Windows.Controls.RadTimePicker.DisplayDateEndProperty, new DateTime() + new TimeSpan(9, 0, 0));
template.VisualTree = spFactory;
template.Seal();

 

Regards,

Auvo

7 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 29 Sep 2015, 08:35 AM
Hello Auvo,

In order to limit the times that could be selected with the desired interval between the time slots you need to use the StartTime and EndTime properties. By setting them to "06:30" and "09:00" the needed limitation will be achieved and the TimeInterval property should be set to "0:10:0" in order to specify the needed interval.

We hope this will help you.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Auvo
Top achievements
Rank 1
answered on 30 Sep 2015, 09:18 AM

Nice and simply solution, it's works :)

 

Thank's,

Auvo

0
Andrew
Top achievements
Rank 1
answered on 03 Aug 2016, 09:24 PM

When I set the start and end time like this: StartTime="04:01" EndTime="13:59" it works as expected.

When I bind those values (see code below) and the converter return the exact same values as above 04:01 and 13:59 nothing happens and the start and end time stays at 12:00 am to 12:00 pm.  Any ideas? 

 

<telerik:RadDateTimePicker.StartTime>
<MultiBinding Converter="{StaticResource DatesToDateConverter}" ConverterParameter="startT">
<Binding Path="ActualStart"/>
<Binding Path="ActualEnd"/>
<Binding Path="Occurrence.Appointment.Status"/>
</MultiBinding>
</telerik:RadDateTimePicker.StartTime>
<telerik:RadDateTimePicker.EndTime>
<MultiBinding Converter="{StaticResource DatesToDateConverter}" ConverterParameter="endT">
<Binding Path="ActualStart"/>
<Binding Path="ActualEnd"/>
<Binding Path="Occurrence.Appointment.Status"/>
</MultiBinding>
</telerik:RadDateTimePicker.EndTime>

0
Nasko
Telerik team
answered on 04 Aug 2016, 07:59 AM
Hi Andrew,

We are not aware of the observed by you issue. Could you please provide us some additional information about your scenario? We have noticed that you are binding also to the "Occurrence.Appointment.Status" property - is the DateTimePicker placed inside ScheduleView or inside one of the Dialogs of RadScheduleView.

Also, providing a code-snippet of the DatesToDateConverter will also be of great help for our further investigation?
 
We are looking forward to hearing from you.

Regards,
Nasko
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Andrew
Top achievements
Rank 1
answered on 04 Aug 2016, 12:40 PM

Nasko,

Yes, you are correct that the code is modifying (and inside) the Telerik.Windows.Controls.ScheduleView.xaml file.  I am changing how the dialog that lets you set a start and end time for event works in the grid: (<Grid x:Name="Details" Grid.Row="2" Margin="6">)

Here is the DatesToDateConverter code:

Public Class DatesToDateConverter
Implements IMultiValueConverter
Public Function Convert(value() As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IMultiValueConverter.Convert
Dim startDate As DateTime = value(0)
Dim endDate As DateTime = value(1)
Dim status As globals.PTOStatus = [Enum].Parse(GetType(globals.PTOStatus), value(2))
Dim param As String = parameter

Select Case status
Case PTOStatus.NotSet
Return startDate.AddDays(7)
Case Else
If param = "start" Then
Return endDate
ElseIf param = "end" Then
Return startDate
ElseIf param = "startT" Then
Return "04:01" 'startDate.AddMinutes(1).ToString("HH:mm") 'allow them to scale down the request to 1 min
ElseIf param = "endT" Then
Return "13:59" 'endDate.AddMinutes(-1).ToString("HH:mm")
Else
Return startDate.AddDays(7) 'numToAdd)
End If
End Select
End Function
Public Function ConvertBack(value As Object, targetTypes() As Type, parameter As Object, culture As Globalization.CultureInfo) As Object() Implements IMultiValueConverter.ConvertBack
Throw New NotImplementedException
End Function
End Class

Thanks so much for your help!

Andrew

0
Nasko
Telerik team
answered on 05 Aug 2016, 10:02 AM
Hello Andrew,

Your converter returns strings when the passed parameter is "startT" or "endT". As the StartTime and EndTime properties are of type TimeSpan the return value should be TimeSpan:
Public Function Convert(ByVal values() As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IMultiValueConverter.Convert
    If parameter.ToString().Equals("startT") Then
        'Return "04:01"
        Return New TimeSpan(4, 1, 0)
    Else
        'Return "13:59"
        Return New TimeSpan(13, 59, 0)
    End If
End Function

Could you please give it a try and let us know if it worked for you?

Hope this helps.

Regards,
Nasko
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Andrew
Top achievements
Rank 1
answered on 05 Aug 2016, 02:20 PM
Everything works as expected now that I am using a timespan - thanks for the help!
Tags
DateTimePicker
Asked by
Auvo
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Auvo
Top achievements
Rank 1
Andrew
Top achievements
Rank 1
Share this question
or