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

Time increment/decrement with +/-

5 Answers 131 Views
TimePicker
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 17 Jun 2010, 04:52 AM
Hi:

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

Sort by
0
Accepted
Kaloyan
Telerik team
answered on 21 Jun 2010, 09:48 AM
Hi Terry,

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
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 Public Issue Tracking system and vote to affect the priority of the items
0
Terry
Top achievements
Rank 1
answered on 21 Jun 2010, 05:55 PM
Thanks, that worked great,l Kaloyan, however, I needed to make a couple of changes.

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;  
            }  
        }  
 
0
Terry
Top achievements
Rank 1
answered on 23 Jun 2010, 12:05 AM
One more related question.  I also have a date picker in the RadGridView and I would like to use + / - to increment /decrement the displayed date.  The column is defined like this:

 

 

 

<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

0
Maya
Telerik team
answered on 24 Jun 2010, 04:33 PM
Hello 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
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 Public Issue Tracking system and vote to affect the priority of the items
0
Nimesh
Top achievements
Rank 1
answered on 29 Jul 2012, 02:08 PM
Can you post your entire code to show how you created the +/- in time? Regards, Nimesh
Tags
TimePicker
Asked by
Terry
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Terry
Top achievements
Rank 1
Maya
Telerik team
Nimesh
Top achievements
Rank 1
Share this question
or