Default to Today when null

3 posts, 0 answers
  1. Rayne
    Rayne avatar
    241 posts
    Member since:
    Sep 2010

    Posted 10 Aug 2011 Link to this post

    My date picker is bound to a DateTime field, but on the UI, the control allows the user to "delete" the value. This causes the validation to throw an error "Value '' cannot be converted". Is there any way to set the control to the current datetime when the user "deletes" the date in the box?

    I'm also having this trouble with a bound combobox that doesn't allow null values. I want the user to be able to type in to select a value, but that means they can also remove the value (which causes the same error).
  2. Rayne
    Rayne avatar
    241 posts
    Member since:
    Sep 2010

    Posted 10 Aug 2011 Link to this post

    I managed to work around it by handling the SelectionChanged event and checking for a SelectedValue. If null, then I set to DateTime.Now.
    I also did the same thing with the combobox. if selected item is null, I set selectedvalue to 0 to trigger the data validation.

    Is this the best way to handle this?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 11 Aug 2011 Link to this post

    Hi Rayne,

    For RadDatePicker you can also use the ParseDateTimeValue event and to implement your custom logic there. As for the RadComboBox I can't think of another way this can be done.

    Best wishes,
    Boyan
    the Telerik team

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

Back to Top