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

Default Date in DateTimePicker

2 Answers 254 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deborah
Top achievements
Rank 1
Deborah asked on 20 Nov 2010, 01:55 AM
Hi -

I have a RadDateTimePicker column in my grid that is initially null. So I am calling SetToNullValue.

But when the user opens the RadDateTimePicker, we would like to set a default date. It appears to use the MinDate for the default date, which my user's don't like.

For example, for a search feature the system defaults to no date criteria (a null value date). But the user can search up to 3 months back (.MinDate = Today.AddMonths(-3)) But the user's don't want to default to this date when the calendar opens.

So is there an easy way to set a default date in this case?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 20 Nov 2010, 02:24 AM
Hello Deborah, long time no see

I usually just do the following, if the selectedDate is null, then just set the selected date to a specific value (so that the calendar will open at that date), and then set it back to the null value so that no date will be selected if the user decides to cancel.
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    var editor = e.ActiveEditor as RadDateTimeEditor;
    if (editor != null)
    {
        var element = editor.EditorElement as RadDateTimeEditorElement;
        if (element.Value == element.NullDate)
        {
            element.Value = DateTime.Now;
            element.Value = element.NullDate;
        }
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Deborah
Top achievements
Rank 1
answered on 23 Nov 2010, 04:58 PM
Hi Emanuel -

Yea, I was at the VSLive conference in Orlando. Took a few extra days off and went to Disney and Harry Potter land with my sister.

Thanks for this. I have not yet tried it. Still trying to get back into things. I'll give it a try and let you know.
Tags
GridView
Asked by
Deborah
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Deborah
Top achievements
Rank 1
Share this question
or