Time increment/decrement with +/-

6 posts, 1 answers
  1. Terry
    Terry avatar
    157 posts
    Member since:
    Jul 2009

    Posted 16 Jun 2010 Link to this post

    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
  2. Answer
    Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 21 Jun 2010 Link to this post

    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
  3. DevCraft banner
  4. Terry
    Terry avatar
    157 posts
    Member since:
    Jul 2009

    Posted 21 Jun 2010 Link to this post

    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;  
                }  
            }  
     
  5. Terry
    Terry avatar
    157 posts
    Member since:
    Jul 2009

    Posted 22 Jun 2010 Link to this post

    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

  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 24 Jun 2010 Link to this post

    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
  7. Nimesh
    Nimesh avatar
    24 posts
    Member since:
    Dec 2007

    Posted 29 Jul 2012 Link to this post

    Can you post your entire code to show how you created the +/- in time? Regards, Nimesh
Back to Top
DevCraft banner