DataTimePicker, Binding and SetToNullValue

5 posts, 0 answers
  1. Chet Musialowski
    Chet Musialowski avatar
    19 posts
    Member since:
    Nov 2009

    Posted 16 Sep 2011 Link to this post

    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


  2. Chet Musialowski
    Chet Musialowski avatar
    19 posts
    Member since:
    Nov 2009

    Posted 16 Sep 2011 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 21 Sep 2011 Link to this post

    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 >>

  5. Don
    Don avatar
    60 posts
    Member since:
    Aug 2010

    Posted 26 Oct 2011 Link to this post

    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.
  6. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 28 Oct 2011 Link to this post

    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.

Back to Top
UI for WinForms is Visual Studio 2017 Ready