i would like to be able to increase the time picker time by 15 minutes by typing a plus or by hitting an up-arrow. Similarly, reduce the time by 15 minutes by hitting the minus key or a down-arrow. Is it possible to do this?
Thanks,
Terry
5 Answers, 1 is accepted
To overcome the task add an EventHandler to the KeyUp event. In the event method handler paste the following code snippet:
private
void
radTimePicker_KeyDown(
object
sender, System.Windows.Input.KeyEventArgs e)
{
if
(!radTimePicker.SelectedTime.HasValue)
{
radTimePicker.SelectedTime = DateTime.Now.TimeOfDay;
}
switch
(e.Key)
{
case
System.Windows.Input.Key.Add:
radTimePicker.SelectedTime = radTimePicker.SelectedTime.Value.Add(TimeSpan.FromMinutes(15));
break
;
case
System.Windows.Input.Key.Subtract:
radTimePicker.SelectedTime = radTimePicker.SelectedTime.Value.Add(TimeSpan.FromMinutes(-15));
break
;
}
}
Best wishes,
Kaloyan
the Telerik team
First, I assume you meant to say KeyDown, not KeyUp, because that is in the name of your event handler.
Second, because the time picker is in a CellEditTemplate, I couldn't use the picker name directly. It wasn't recognized, so I casted the sender to a time picker to get the object.
Third, I found I had to set e.Handled = true to avoid getting the plus or minus added in the time picker field.
In case anyone is interested, here is the revised code:
private void TimePicker_KeyDown( object sender, KeyEventArgs e ) |
{ |
Telerik.Windows.Controls.RadTimePicker TimePicker = sender as Telerik.Windows.Controls.RadTimePicker; |
if ( !TimePicker.SelectedTime.HasValue ) |
{ |
TimePicker.SelectedTime = DateTime.Now.TimeOfDay; |
} |
switch ( e.Key ) |
{ |
case System.Windows.Input.Key.Add: |
TimePicker.SelectedTime = TimePicker.SelectedTime.Value.Add( TimeSpan.FromMinutes( 15 ) ); |
e.Handled = true; |
break; |
case System.Windows.Input.Key.Subtract: |
TimePicker.SelectedTime = TimePicker.SelectedTime.Value.Add( TimeSpan.FromMinutes( -15 ) ); |
e.Handled = true; |
break; |
} |
} |
<radGridView:GridViewDataColumn Header="Date" DataMemberBinding="{Binding StartDate}" DataFormatString="{}{0:d}" />
(If I use a separate CellEditTemplate I can't get the tabbing behavior to work properly .)
There is no click event available for the column, so how would I get the + / - behavior in this case?
Thanks,
Terry
You can create your own custom column with the desired view and functionality. I am sending you a sample project demonstrating the proposed solution. Here the specific column is created in the class AdvancedDatePickerColumn.cs that predefines the default method CreateCellEditElement() and the binding is made through CreateValueBinding(). Once being added in your application, you can instantiate it in MainPage.xaml as follows:
<
local:AdvancedDatePickerColumn
DataMemberBinding
=
"{Binding BirthDay}"
DataFormatString
=
"{}{0:d}"
/>
Sincerely yours,
Maya
the Telerik team