Negative values in TimeSpanPicker

3 posts, 1 answers
  1. Steve
    Steve avatar
    20 posts
    Member since:
    Jan 2011

    Posted 15 Feb 2016 Link to this post


     I was wondering if there is any way to set up a TimeSpanPicker so that negative values can be provided?

    I tried setting the "Minimum" option on the components to a negative value, but it seems this isn't respected and the minimum remains at 0.

     Any help would be appreciated


  2. Answer
    Polya avatar
    255 posts

    Posted 16 Feb 2016 Link to this post

    Hello Steve,

    With the current implementation of RadTimeSpanPicker - all StepTimeSpanComponents (which includes the default components for day, hour, minute, second and millisecond) have minimum value of 0 for their Minimum and Maximum properties. That said when you set the Minimum to be less than 0 it will be processed as 0.
    In order to achieve the desired you can create a custom TimeSpanComponentBase for each component you wish to use with negative values. Please find attached a sample project demonstrating this approach. In it I've created a NegativeHourTimeSpanComponent. In the overriden GetTicksFromItem() method I return correct ticks for the passed value, which can be a negative number as well.

    As our built in implementation only works with positive numbers I would like to ask you to please share more information on your scenario and what caused the need for negative TimeSpan values.
    If you think we should improve the implementation of our default components to also include negative numbers you can add a feature request in our feedback portal:

    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
  3. Steve
    Steve avatar
    20 posts
    Member since:
    Jan 2011

    Posted 16 Feb 2016 in reply to Polya Link to this post

    Thanks Polya, that solution works great.

    To elaborate on the situation, it was needed as part of a time tracking program, for users to add or remove time. I actually settled yesterday on a toggle between adding or removing time, along with a TimeSpanPicker showing only positive values, which works well for this specific situation, but I could also see a need for a negative value in a TimeSpanPicker if we were to use it for inline editing in a GridView, for example.

Back to Top