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

DataTimePicker, Binding and SetToNullValue

4 Answers 283 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Chet Musialowski
Top achievements
Rank 1
Chet Musialowski asked on 16 Sep 2011, 08:55 PM
Hello,

Prior to Q2 2011 SP1 (version 2011.2.11.831), we had no problems with the subclass of the RadDateTimePicker we created, but since then, we are having issues with SetToNullValue() and DataBinding.  We were using RadControls for WinForms Q3 2010 prior to updating.  

When we call this.radDateTimePicker1.SetToNullValue(), it appears to "null" out the control, but when you move to the next control, the datetime control goes from not having a value displayed to displaying the value before SetToNullValue() was called.  In the bound source, the column contains the NullDate value while the control's Value property has the value from before SetToNullValue() was called

I have also come across inconsistency of values when the control is bound to a dataset from SQL Server.  From tracing thru the code, we are able to determine that the correct date is in the Value property, but when we looked at the DataTable its bound to, the value there is different.

The code has not changed and I have been able to replicate the SetToNullValue behavior in a new project using just the RAD controls. 

Any help is appreciated,
Chet


4 Answers, 1 is accepted

Sort by
0
Chet Musialowski
Top achievements
Rank 1
answered on 16 Sep 2011, 09:26 PM
Updated information:

I've also found that if the value in the BindingSource is null, when you tab thru the DateTimePicker, it displays the value from the .Designer code file (in my case it is 9/16/2011 and the DateTimePicker.Value property also is 9/16/2011 while the BindingSource still shows nothing and its RowState is "Unchanged"

Chet
0
Peter
Telerik team
answered on 21 Sep 2011, 09:43 AM
Hello Chet,

We are aware of the second issue and will provide a fix for it in our next release. This happens because .NET simple data-binding internally converts NULL value to DBNULL and RadMaskedEditBix does not cover this scenario.

The method SetToNullValue() sets the Value of RadDateTimePicket to NullDate. In this case when the control is in focus there is a value and this value allows user to modify/enter the date. In case the focus is out of the control, the control stays empty or shows its NullText (if it is set).

If you have further questions, I would be glad to help.

Greetings,
Peter
the Telerik team

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

0
Don
Top achievements
Rank 1
answered on 26 Oct 2011, 06:43 PM
The only thing that has worked for me in keeping the RadMaskedEditBox empty when no value is entered by the user is to set the MinimumDate value to a date I know will not be used, say 1/1/1900, and then check for this date value in the ValueChanged event for my DateTimePicker control. If that date is the value, I reset the DateTimePicker to NULL, using the SetToNullValue() method, and set the text value of the control to an empty string, "" in VB.

The check looks like this for one of my controls:
If udtDtofDeath.Value = #1/1/1900# Then
    udtDtofDeath.DateTimePickerElement.SetToNullValue()
    udtDtofDeath.DateTimePickerElement.NullText = ""
    udtDtofDeath.Text = ""
End If

This is the only way I have found that keeps the RadMaskedEditBox blank when a user inadvertently clicks on it or tabs into it and does not enter a value of their own.
0
Peter
Telerik team
answered on 28 Oct 2011, 12:52 PM
Hi Don,

Thank you for sharing your solution with us.

I would like to share that you can set NullableValue property to Nothing. When the control is in focus, it will show date to allow user to enter/edit the value. When the control is out of focus, the control stays empty.

All the best,
Peter
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Chet Musialowski
Top achievements
Rank 1
Answers by
Chet Musialowski
Top achievements
Rank 1
Peter
Telerik team
Don
Top achievements
Rank 1
Share this question
or