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

Hide if DateTime value is minValue

4 Answers 291 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 25 Oct 2010, 10:55 PM
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.

4 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 26 Oct 2010, 03:47 AM
For those who need solution, change the DateTime type to DateTime? type in the object.  It would do the trick.
0
Kaloyan
Telerik team
answered on 28 Oct 2010, 08:05 AM
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
0
Edward
Top achievements
Rank 1
answered on 15 Jun 2011, 03:33 PM
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.
0
Edward
Top achievements
Rank 1
answered on 16 Jun 2011, 08:30 PM
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;
    }
}
Tags
DatePicker
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Kaloyan
Telerik team
Edward
Top achievements
Rank 1
Share this question
or