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

Default Start Date

36 Answers 1123 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Emre Ozan Alkan
Top achievements
Rank 2
Emre Ozan Alkan asked on 31 Aug 2009, 12:32 PM
I'm using Q2 2009 SP1 (2009.2.9.729) release of Telerik. And have form with date time picker. When I try to select a date,it pops up with  January 1990. I want to change that user should see current mounth and year. Otherwise user has to go till the 1987 to select his birthday. I've searched on google and in this forum but unfortunately didnt find the solution.

36 Answers, 1 is accepted

Sort by
0
Boyko Markov
Telerik team
answered on 31 Aug 2009, 02:22 PM
Hi Emre Ozan Alkan,

You can modify the Value property of RadDatetimePicker and it will display the Value which you have entered. For example, you can do the following:

          RadDateTimePicker dateTimePicker = new RadDateTimePicker();
           this.Controls.Add(dateTimePicker);
           dateTimePicker.Value = new DateTime(2009, 5, 1);

Please write me back if you need more information.

I hope this helps.


Greetings,
Boyko Markov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Emre Ozan Alkan
Top achievements
Rank 2
answered on 01 Sep 2009, 10:02 AM
Thanks for that solution it works well. Actually I have shared form shown up after new user register that user fill his information if he is new and save the values to our business object.But there is also search users function that we find user and open same form and show his information that entered before, with data binding. If new user register and show the form, all texts, combo boxes etc are empty default also no date in date time picker.As your solution If I set datetimepciker.value = DateTime.Now(), thats fine with new registration and start from todays date(also show the time in its combobox but anyway) but when we also look the current users information their birthday is change with todays date as u assume :). Will you have some issue or tickets or request from users for that problem ? Cause defaultly starts from 1900 ? unless your solution used, but thats also puts value to combobox which may not good for some people. Thanks.
0
Boyko Markov
Telerik team
answered on 04 Sep 2009, 07:29 AM
Hello Emre Ozan Alkan,

Thank you for your feedback. Could you please send me a sample project which reproduces the issue as I have not been able to reproduce it locally? This could be related to something specific to your project so any information about this would be very helpful. In the previous ticket I have just told you the way to modify the Value property which will automatically set the correct Value. I'm looking forward to your reply.

All the best,
Boyko Markov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Imran
Top achievements
Rank 1
answered on 16 Jun 2010, 04:31 AM
I am using the Raddatetimepicker in my form.
I want the control to display nothing in it initially.
When user clicks to select the date, he is seeing some month in 1900 !! !!
Now user is forced to keep on clicking for 10 minutes to come to the todays date or something within a year 's date from today.

I want the control to show initially no date ... 
but when user clicks it.. the pop up should show the drop down calender to show todays month .. so that user can select any date within this month or change the months closer to this month etc...i.e any other month within the same year...   
If the user does't select any date and closes the popup then the text box should not have any date and should show empty  value.
How to do it ??

I guess Boyko Markov 's posting of august 31, 2009 will change the value to (2009, 5, 1). I dont' want that to happen....
any suggestion..

IK
0
Accepted
Stefan
Telerik team
answered on 21 Jun 2010, 02:59 PM
Hello Imran,

Thank you for writing.

The Value property of RadDateTimePicker is of type DateTime. Since DateTime is a Value Type (but not a Reference Type), you can't assign null or Nothing to it. The default behavior of RadDateTimePicker is to get the MinDate value and set it to the NullDate property. By default this value is 1/1/1900. 

In order to get the current month in the RadCalendar dropdown, you should access and manipulate the RadCalendar instance. Please consider the following code snippet:
public Form1()
{
    InitializeComponent();
  
    this.radDateTimePicker1.SetToNullValue();
    this.radDateTimePicker1.DateTimePickerElement.Opened += new EventHandler(DateTimePickerElement_Opened);
}
  
void DateTimePickerElement_Opened(object sender, EventArgs e)
{
    RadDateTimePickerCalendar calendarBehavior = this.radDateTimePicker1.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar;
    RadCalendar calendar = calendarBehavior.Calendar as RadCalendar;
    calendar.FocusedDate = DateTime.Now;
}

I hope this helps.

Kind regards,
Stefan
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
Emre Ozan Alkan
Top achievements
Rank 2
answered on 21 Jun 2010, 03:33 PM
Thank you Stefan, that really solve the problem in a good manner. Our old approach was setting date time picker component like
dtp.NullDate = DateTime.Today.AddSeconds(1); and then calling dtp.SetToNullValue() or reverse anyway. Anyway, really nice to see that code snippet.
0
Carol Watson
Top achievements
Rank 1
answered on 02 Jul 2010, 06:22 AM
Hi, Could you repost this example using vb code instead?

Thanks
0
Emre Ozan Alkan
Top achievements
Rank 2
answered on 02 Jul 2010, 07:38 AM
Carol Watson how about using Telerik code converter ? => http://converter.telerik.com/

This converts Stefan's code snippet to =>

Public Sub New()
    InitializeComponent()

    Me.radDateTimePicker1.SetToNullValue()
    Me.radDateTimePicker1.DateTimePickerElement.Opened += New EventHandler(DateTimePickerElement_Opened)
End Sub

Private Sub DateTimePickerElement_Opened(sender As Object, e As EventArgs)
    Dim calendarBehavior As RadDateTimePickerCalendar = TryCast(Me.radDateTimePicker1.DateTimePickerElement.GetCurrentBehavior(), RadDateTimePickerCalendar)
    Dim calendar As RadCalendar = TryCast(calendarBehavior.Calendar, RadCalendar)
    calendar.FocusedDate = DateTime.Now
End Sub

'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik, @toddanglin
'Facebook: facebook.com/telerik
'=======================================================

0
Stefan
Telerik team
answered on 02 Jul 2010, 04:32 PM
Hi Emre Ozan Alkan,

Here is the ported code to VB:
 
Imports Telerik.WinControls.UI
 
Public Class Form1
    Public Sub New()
        InitializeComponent()
        RadDateTimePicker1.SetToNullValue()
 
        AddHandler RadDateTimePicker1.DateTimePickerElement.Opened, AddressOf DateTimePickerElement_Opened
 
    End Sub
 
    Sub DateTimePickerElement_Opened(ByVal sender As Object, ByVal e As EventArgs)
        Dim calendarBehavior As RadDateTimePickerCalendar = TryCast(Me.RadDateTimePicker1.DateTimePickerElement.GetCurrentBehavior(), RadDateTimePickerCalendar)
        Dim calendar As RadCalendar = TryCast(calendarBehavior.Calendar, RadCalendar)
        calendar.FocusedDate = DateTime.Now
 
    End Sub
End Class

 

Kind regards,
Stefan
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
Sheraz Naseeb
Top achievements
Rank 1
answered on 29 Sep 2010, 05:53 PM
Hi Telerik Team,

I like the solution you provided to show up today's date, but can we do it the way Microsoft's date time picker does it.

For example, if the RadDateTimePicker is showing the date 15/05/2010 and today is 29/09/2010, when user opens the RadDateTimePicker it should stay in the month May but on the bottom or somewhere else it shows today's date which is 29/09/2010 so when user clicks there it jumps to today's date.

Please let me know if its possible if so then how to do that.

Many thanks,

Sheraz
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 30 Sep 2010, 07:45 AM
Hello Sheraz,

In order to show today's button you can do the following:

var datePickerCalendarBehavior =
                this.radDateTimePicker.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar;
            calendar = datePickerCalendarBehavior.Calendar;
            calendar.AllowMultipleSelect = false;
            calendar.ShowFooter = true;
            calendar.CalendarElement.CalendarStatusElement.Text = string.Empty;
            datePickerCalendarBehavior.DropDownMinSize = new Size(250, 250);

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

Best Regards,
Emanuel Varga
0
Sheraz Naseeb
Top achievements
Rank 1
answered on 30 Sep 2010, 11:30 AM
Thanks Emanuel,

It works...
0
Deborah
Top achievements
Rank 1
answered on 26 Oct 2010, 10:39 PM
This also gives me a cool "Clear" button. I assumed that would clear the selection, but it does not.

Do I have to add some code to get the Clear button to work from the date drop down?
0
Emanuel Varga
Top achievements
Rank 1
answered on 27 Oct 2010, 02:00 PM
Hello Deborah,

Sorry for the late response, but you can handle the ClearButton.Click, by using my previous code +
calendar.ClearButton.Click += delegate
{
    calendar.SelectedDate = DateTime.Now;
};

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

Best Regards,
Emanuel Varga
0
Deborah
Top achievements
Rank 1
answered on 27 Oct 2010, 03:43 PM
How is that then any different than clicking the Today button? I thought clear was supposed to clear the selection. So shouldn't I set the Value to null? Or call that SetNull method?

Thanks!
0
Emanuel Varga
Top achievements
Rank 1
answered on 27 Oct 2010, 03:46 PM
Hello again Deborah,

I have just provided a way for you to decide what that button should do, what date to set when clicked, what text should that button display and so on.

Best Regards,
Emanuel Varga
0
Deborah
Top achievements
Rank 1
answered on 27 Oct 2010, 03:59 PM
Thanks!

I sure wish that the DatePicker worked with a Nullable structure because the null handling just does not seem to work quite right.

Thanks again for your help. I am trying this now.
0
Deborah
Top achievements
Rank 1
answered on 27 Oct 2010, 04:13 PM
Is there a way to then close the drop down? I would like the Today button to pick today and close. I would like the Clear button to clear to a null value and close.

I have the code to set to a null value, but I cannot find a method to call to close the calendar drop down.

Thanks!
0
Emanuel Varga
Top achievements
Rank 1
answered on 27 Oct 2010, 04:17 PM
Hello Deborah,

Just handle the TodayButton.Click also, like so:
calendar.TodayButton.Click += delegate
{
    calendar.SelectedDate = DateTime.Now;
};

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

Best Regards,
Emanuel Varga
0
Deborah
Top achievements
Rank 1
answered on 27 Oct 2010, 04:23 PM

Hey! I am smart enough to figure out how to do a Today event handler once I know how to do Clear. :-)

That was not my question.

I want to know how to CLOSE the drop down when the user clicks the button.

I tried this, and it makes the calendar go away, but then it won't come up correctly the next time. There must be a way to tell the calendar to close properly?

AddHandler calendar.ClearButton.Click,
    Sub()
        dt.SetToNullValue()
        calendar.Visible = False
    End Sub


Is there a way to close the datetime picker drop down from the buttons properly without having to make it invisible?

0
Emanuel Varga
Top achievements
Rank 1
answered on 27 Oct 2010, 04:27 PM
Hello again,

Sorry, i think you misunderstood, if you handle the Today button like that, after setting the today date it will close the dropdown, just like that.
Or at least that is what happens in my tests.

Sorry again...

Best Regards,
Emanuel Varga
0
Emanuel Varga
Top achievements
Rank 1
answered on 27 Oct 2010, 04:28 PM
Forgot to mention, you don't have to call calendar.Visible = false in order for it to close.
0
Deborah
Top achievements
Rank 1
answered on 27 Oct 2010, 04:30 PM
Never mind. I think I figured it out:

AddHandler calendar.ClearButton.Click,
    Sub()
        DirectCast(dt.DateTimePickerElement.GetCurrentBehavior, RadDateTimePickerCalendar).PopupControl.HideControl()
        dt.SetToNullValue()
    End Sub

Though this is a bit nasty. You'd think it would be more "developer-friendly" if Telerik would just add a Close method. :-)

Thanks for your help!
0
Emanuel Varga
Top achievements
Rank 1
answered on 27 Oct 2010, 04:31 PM
Hello again,

But you don't have to do that, it is closing after setting the value...

Best Regards,
Emanuel Varga
0
Deborah
Top achievements
Rank 1
answered on 27 Oct 2010, 04:33 PM
For my null button, that is not working.

Maybe setting dt.SettoNullValue is not correct?

I have not tried the today code yet, but I will.

(And Sorry, I thought you were poking fun!<G>)
0
Emanuel Varga
Top achievements
Rank 1
answered on 27 Oct 2010, 04:36 PM
Hello again,

Don't use set to null, just assign the NullDate to the SelectedDate property and it will close, and the same for Today with DateTime.Now.

(*update very very offtopic, but i was very curios and you don't have to answer, but are you by any change DeborahK from MDSN forums?)

Best Regards,
Emanuel Varga
0
Accepted
Deborah
Top achievements
Rank 1
answered on 27 Oct 2010, 04:40 PM
This Today code works:

AddHandler calendar.TodayButton.Click, Sub() calendar.SelectedDate = DateTime.Now()

And this Clear button code works:

AddHandler calendar.ClearButton.Click, Sub() calendar.SelectedDate = dt.NullDate

Thanks again for your help!
0
Emanuel Varga
Top achievements
Rank 1
answered on 27 Oct 2010, 04:42 PM
Glad to be able to help, also I've updated my previous message with maybe a very stupid question but i was curios.

Best Regards,
Emanuel Varga
0
Deborah
Top achievements
Rank 1
answered on 27 Oct 2010, 04:56 PM
Yes. And I have been seeing your name there quite a bit as well. :-)
0
Emanuel Varga
Top achievements
Rank 1
answered on 27 Oct 2010, 05:16 PM
I had a feeling that's why I asked.

And yes, just trying to expand my horizon and in the same time help people reach their goals :-).

Thank you for your honesty,
Best Regards,
Emanuel Varga

0
Venkat
Top achievements
Rank 1
answered on 27 Jun 2012, 06:41 AM
Hi i am using raddatetimepicker verson=2011.1.519.35 in asp.net i want to set todays date to it...
it is possible with ajaxcalender extender like
function clientShowing(sender, args) {
            if (new Date($get("HiddenField1").value) != null) {
                sender.set_todaysDate(new Date($get("HiddenField1").value));
            }
        }
<form id="form1" runat="server">
    <div>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:calendarextender ID="CalendarExtender1" runat="server" Enabled="True" Format="dd/MM/yyyy"
            TargetControlID="TextBox1" OnClientShowing="clientShowing"
            PopupPosition="BottomLeft">
        </asp:calendarextender>
        <asp:HiddenField ID="HiddenField1" runat="server" />
        
    </div>
    </form>
it means whatever date in hiddenfield, i want to set it to raddatetimepicker as today date...
how to do it for asp.net...
0
Stefan
Telerik team
answered on 27 Jun 2012, 07:29 AM
Hi Venkat,

This forum concerns RadCalendar for WinForms. Please address your question in the appropriate forums, in order to get your answer.
 
All the best,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
JanwalkarPooja
Top achievements
Rank 2
answered on 10 May 2013, 07:02 AM
Hi Telerik Team,

Is it possible to manipulate System date and time with other selected Location/City combo-box control.
Generally,Calendar control always highlighted current date according to system date and time.
But in my project I don't want this behavior.  I want that my calendar should follow or highlighted current date with selected different city/location view.

How do I programmatically or XAML Style/Theme through achieve this scenario?

I am looking forward you reply.

Regards,
Pooja
0
Stefan
Telerik team
answered on 14 May 2013, 12:25 PM
Hi Pooja,

It seems that your question concerns the WPF/Silverlight calendar. If so, please post in in the corresponding forums: http://www.telerik.com/community/forums/silverlight.aspx.


Greetings,
Stefan
the Telerik team
RadChart for WinForms is obsolete. Now what?
0
JanwalkarPooja
Top achievements
Rank 2
answered on 14 May 2013, 12:52 PM
Hi Team,

I have posted my issue on given http://www.telerik.com/community/forums/silverlight.aspx. path as name Change the default Date with mentioned link http://www.telerik.com/community/forums/silverlight/calendar/change-the-default-start-date.aspx

kindly look into this issue and let me know.

Looking forward your reply.

Regards,
Pooja
0
Stefan
Telerik team
answered on 14 May 2013, 01:18 PM
Thank you for posting the question in the appropriate section. I am sure that the community or the guys from the Silverlight division will address it accordingly.
 
All the best,
Stefan
the Telerik team
RadChart for WinForms is obsolete. Now what?
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Emre Ozan Alkan
Top achievements
Rank 2
Answers by
Boyko Markov
Telerik team
Emre Ozan Alkan
Top achievements
Rank 2
Imran
Top achievements
Rank 1
Stefan
Telerik team
Carol Watson
Top achievements
Rank 1
Sheraz Naseeb
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Deborah
Top achievements
Rank 1
Venkat
Top achievements
Rank 1
JanwalkarPooja
Top achievements
Rank 2
Share this question
or