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

Q2 2011 DateTimePicker nulldate

10 Answers 227 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
David A.
Top achievements
Rank 1
David A. asked on 02 Aug 2011, 08:43 PM
Hi,

With Q2 2011 DateTimePicker if I set the NullDate to DateTime.Today.AddSeconds(1) I can not set the date to today's date as it shows up blank (null) as soon as I choose todays date. If I choose the day before or after today it works.  Did something break in this version or am I missing something?  Also, it would be nice if by default if the user hits the delete key anywhere within the date text that the value is set to null and the textbox is cleared.  It is a problem to our users when the delete button is hit in the year field and it just changes to 0001 as in your examples.

I followed this thread to set nulldate to today to avoid having the calendar show or 0001 for the year. http://www.telerik.com/community/forums/winforms/calendar-and-datetimepicker/setting-mindate-but-not-value.aspx

Thanks!

10 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 04 Aug 2011, 04:18 PM
Hello David A.,

I can confirm the issue.

We will address this misbehavior in our SP release at the end of August. We have added points to your account for the report.

I would like to inform you that in Q2 2011 we provided support for Null Value in RadDateTime/RadMaskedEditBox. So, the following code should show an DateTimePicker with "Enter Date" text:

this.radDateTimePicker1.NullText = "Enter Date";
this.radDateTimePicker1.NullableValue = null;

Do not hesitate to contact us if you have other questions. Greetings,
Peter
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
hartley
Top achievements
Rank 1
answered on 04 Aug 2011, 05:27 PM
Hi, 

I have a question for Peter, would NullableValue be the correct property to bind data to? Does it accept 
DBNull.Value as well?

Thanks for your time.
0
David A.
Top achievements
Rank 1
answered on 04 Aug 2011, 05:34 PM
I was unable to bind via dataset to NullableValue.  I had to subclass the control and add a property called "BindableValue" to work with DBNull.
object _bindableValue=DBNull.Value ;
        [Browsable(false), Bindable(true),  Description("Gets or sets the date/time bindable value assigned to the control.")]
        public object BindableValue
        {
            get
            {
                if (this.Value == this.NullDate)
                    _bindableValue = DBNull.Value;
                else
                    _bindableValue = this.Value;
 
                return _bindableValue;
            }
            
            set
            {
                _bindableValue = (value ?? DBNull.Value);
 
                if (_bindableValue != DBNull.Value)
                    this.Value = (DateTime)value;
                else
                    this.Value = this.NullDate;
 
                this.OnNotifyPropertyChanged("BindableValue");
            }
        }
0
hartley
Top achievements
Rank 1
answered on 04 Aug 2011, 05:47 PM
I was working around this problem yesterday and decided to have the controls Binding object do the conversion by setting its NullValue during initialization.
this.radDateTimePicker1.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.tblClientBindingSource, "ClientSinceDate", true, System.Windows.Forms.DataSourceUpdateMode.OnValidation, System.DateTime.Now.Date.AddSeconds(1), ""));
this.radDateTimePicker1.NullDate = System.DateTime.Now.Date.AddSeconds(1);
this.radDateTimePicker1.NullText = "";
this.radDateTimePicker1.Value = System.DateTime.Now.Date;

 I posted more detailed explanations here :
http://www.telerik.com/community/forums/winforms/calendar-and-datetimepicker/raddatepicker-and-null-values.aspx#1747985
and here:
http://www.telerik.com/community/code-library/winforms/editors/nullabledatetimepicker.aspx#1748021

0
David A.
Top achievements
Rank 1
answered on 04 Aug 2011, 06:11 PM
Interesting posts hartley.  Will that set "ClientSinceDate" to DBNull through databinding without a date value?
0
hartley
Top achievements
Rank 1
answered on 04 Aug 2011, 06:44 PM
Yes, the "ClientSinceDate" value in my SQL Server table becomes <null>, when the record is saved, so the data table value must have been set to DBNull. This will happen when you press the Delete key in the control.

I set the Binding's NullValue and the DatePicker's NullDate to the same value. So the binding changes DBNull into NullDate when it sets the value, and changes NullDate into DBNull when it receives a value.

Remember to set this Databinding in the code file, not the designer file. Visual Studio will overwrite it if you make any changes to the form.
0
Peter
Telerik team
answered on 09 Aug 2011, 04:10 PM
Hello everyone,

Thank you for writing.

Getting straight to the questions, we do not support DBNull value at the moment because DBNull.Value cannot be assigned to NullableValue property (of type DataTime).

The upcoming Service Pack will contain improvements in the binding logic which will make NullableValue the correct property to bind data. We also plan to improve the NullableDate: RadDateTimePicker will check only the Date part of this property and ignore the Time part. I will be happy to hear any comments or concerns that you might have about this change.

I hope you find my answer useful. Let me know if you have further questions.

Greetings,
Peter
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
David A.
Top achievements
Rank 1
answered on 10 Aug 2011, 05:39 PM

Hi Peter,

I look forward to these changes. 

In order to handle a DBNull I inherited the control and added a bindable property (BindableValue) of type object.  The other two issues that I have with this control is when hitting the delete key in the year field makes the year 0001 (or mindate year) and hitting delete in month/day sets it to 1.  I prefer to have the control set to null if delete is hit at all in the control:

public override void OnKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyData == System.Windows.Forms.Keys.Delete)
            {
                this.SetToNullValue();
                this.OnNotifyPropertyChanged("BindableValue");
                e.Handled = true;
            }
            else
                base.OnKeyDown(sender, e);
 
        }

When the value is null and the user clicks the drop down, the calendar displays the mindate.  This has been discussed on other threads, but my solution was this:

protected override void OnOpening(CancelEventArgs args)
        {
            base.OnOpening(args);
 
            if (this.Value == this.NullDate)
                this.Value = DateTime.Today;
        }

It would be ideal if something like the above was implemented in the service pack or a future release.  I greatly appreciate your concern.

David A.

0
Peter
Telerik team
answered on 15 Aug 2011, 04:46 PM
Hello David A.,

Thank you very much for the suggestion.

We will do our best to implement this behavior in one of our next releases.
I think that this behavior should be switched on and off by a property, because this will be a breaking change for the users.

I have updated your Telerik points for the cooperation.

Best wishes,
Peter
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Peter
Telerik team
answered on 02 Sep 2011, 03:38 PM
Hello David A.,

I would like to inform that we improved this behavior in Q1 2011 SP1. Feel free to download this version from Your Account and give it a try.

Regards,
Peter
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
David A.
Top achievements
Rank 1
Answers by
Peter
Telerik team
hartley
Top achievements
Rank 1
David A.
Top achievements
Rank 1
Share this question
or