Time picker won't take nulls

7 posts, 1 answers
  1. John
    John avatar
    60 posts
    Member since:
    Nov 2006

    Posted 22 Feb 2013 Link to this post

    how do i get a TimePicker to take a null value?  not the datetime picker, just the time one.  i have the date one working.

    i tried setting it to null
    timSatStart.Value = null;
    
    and it didn't work, i also tried binding a nullable datetime from the database to it and it won't work either.

    both ways set the time picker to the current time.

    thanks.
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 27 Feb 2013 Link to this post

    Hi John,

    Thank you for writing.

    RadTimePicker accepts null value in my tests - please refer to the attached video (opens in browser). If you continue experiencing the undesired behavior, please get back to me with the exact steps that I need to follow in order to reproduce it. Alternatively, open a new support ticket and attach a sample project there.
     
    Regards,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. John
    John avatar
    60 posts
    Member since:
    Nov 2006

    Posted 27 Feb 2013 Link to this post

    Thanks stefan,

    I upgraded to 2013 q1 and part of the problem went away.  i can set the .value property and the control blanks out like it should.

    i have 2 other problems with this now.  

    1.  i still can't bind to the value property with a null value.  it puts the time that the control was dropped on the form into it.

    i've tried with 
    timSatLunchEnd.DataBindings.Add("Value", _bs, "StdOfficeHours.SatEndLunch"trueDataSourceUpdateMode.OnPropertyChanged, null);
    
    and
    timSatLunchEnd.DataBindings.Add("Value", _bs, "StdOfficeHours.SatEndLunch"trueDataSourceUpdateMode.OnPropertyChanged);
    

    2.  how can the end user blank the date out?  if i push backspace or delete in the box, it just goes to 12 AM.  i want it to clear it self out and propagate a null to the datasource.

    thanks

    EDIT:
    i fixed #1 so that just leaves #2.
    Thanks.
  5. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 04 Mar 2013 Link to this post

    Hello John,

    Thank you for writing back.

    To set the value of the control to null when the Delete key is pressed for example, you can use the KeyUp event of the control:
    void radTimePicker1_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.KeyData == Keys.Delete)
        {
            radTimePicker1.Value = null;
        }
    }

    I hope that you find this information useful.
     

    Kind regards,
    Stefan
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Join us for a FREE webinar to see all the new stuff in action.

    Interested, but can’t attend? Register anyway and we’ll send you the recording.
  6. Matt
    Matt avatar
    10 posts
    Member since:
    Jul 2011

    Posted 10 Jul 2013 Link to this post

    Hi John,

    How did you manage to solve the binding issue (ie. problem 1)?

    Thanks,

    Matt
  7. John
    John avatar
    60 posts
    Member since:
    Nov 2006

    Posted 10 Jul 2013 Link to this post

    it's been a while, but i think the fix was to inherit from their RadTimePicker and then override the value property.  here's what i have for it
    public new DateTime? Value
            {
                get
                {
                    if (base.Value.HasValue == false) return null;
                    var dt = base.Value.Value;
                    return new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0, 0);
                }
                set
                {
                    if (value == null)
                        base.Value = value;
                    else
                    {
                        var dt = value.Value;
                        base.Value = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0, 0);
                    }
                }
            }
  8. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 11 Jul 2013 Link to this post

    Hello guys,

    I just wanted to mention that binding to the Value should be working out of the box with nulls. Please try with the latest version and let me know if you experience any issues, so we can investigate them.
     

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready