Hide if DateTime value is minValue

5 posts, 0 answers
  1. John
    John avatar
    34 posts
    Member since:
    Oct 2010

    Posted 25 Oct 2010 Link to this post

    Telerikers,
    I do have a radgridview with one RadDateTimepicker control on it.  the RadDateTimepicker control binds it correctly in EDIT mode.  However, when the data returns as minvalue from DB (1/1/0001), I would like to hide it and keep the RadDateTimepicker box blank. 

    See attachment for details. http://i12.photobucket.com/albums/a201/le9569/1-3.png

    Your guidance is appreciated.
    John.
  2. John
    John avatar
    34 posts
    Member since:
    Oct 2010

    Posted 25 Oct 2010 Link to this post

    For those who need solution, change the DateTime type to DateTime? type in the object.  It would do the trick.
  3. DevCraft banner
  4. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 28 Oct 2010 Link to this post

    Hello John,

    In addition to this use the SelectedValue as a recommendation instead of the SelectedDate.

    Kind regards,
    Kaloyan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Edward
    Edward  avatar
    32 posts
    Member since:
    Jan 2008

    Posted 15 Jun 2011 Link to this post

    Just wondering if anyone has some other solution?  Since the database column is not nullable, the entity model just sue DateTime instead of DateTime?.  So everytime I try to create a new object it will be bound to the MinValue.
  6. Edward
    Edward  avatar
    32 posts
    Member since:
    Jan 2008

    Posted 16 Jun 2011 Link to this post

    Add a converter should work:

    public class MinDateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return null;
     
            if (value.GetType() == typeof(DateTime))
            {
                var d = DateTime.Parse(value.ToString());
                if (d == DateTime.MinValue) return null;
                return d;
            }
     
            return null;
        }
     
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not needed;
            if (value == null)
                return DateTime.MinValue;
     
            return value;
        }
    }
Back to Top
DevCraft banner