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

Time picker won't take nulls

6 Answers 62 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 22 Feb 2013, 07:52 PM
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.

6 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 27 Feb 2013, 12:14 PM
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.
0
John
Top achievements
Rank 1
answered on 27 Feb 2013, 01:41 PM
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.
0
Accepted
Stefan
Telerik team
answered on 04 Mar 2013, 07:45 AM
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.
0
Matt
Top achievements
Rank 1
answered on 10 Jul 2013, 07:58 AM
Hi John,

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

Thanks,

Matt
0
John
Top achievements
Rank 1
answered on 10 Jul 2013, 04:47 PM
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);
                }
            }
        }
0
Stefan
Telerik team
answered on 11 Jul 2013, 01:03 PM
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 >>
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
John
Top achievements
Rank 1
Answers by
Stefan
Telerik team
John
Top achievements
Rank 1
Matt
Top achievements
Rank 1
Share this question
or