Default Start Date

37 posts, 3 answers
  1. Emre Ozan Alkan
    Emre Ozan Alkan avatar
    9 posts
    Member since:
    Jul 2009

    Posted 31 Aug 2009 Link to this post

    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.
  2. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 31 Aug 2009 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Emre Ozan Alkan
    Emre Ozan Alkan avatar
    9 posts
    Member since:
    Jul 2009

    Posted 01 Sep 2009 Link to this post

    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.
  5. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 04 Sep 2009 Link to this post

    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.
  6. Imran
    Imran avatar
    13 posts
    Member since:
    Jun 2010

    Posted 15 Jun 2010 Link to this post

    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
  7. Answer
    Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 21 Jun 2010 Link to this post

    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
  8. Emre Ozan Alkan
    Emre Ozan Alkan avatar
    9 posts
    Member since:
    Jul 2009

    Posted 21 Jun 2010 Link to this post

    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.
  9. Carol Watson
    Carol Watson avatar
    21 posts
    Member since:
    Jan 2010

    Posted 02 Jul 2010 Link to this post

    Hi, Could you repost this example using vb code instead?

    Thanks
  10. Emre Ozan Alkan
    Emre Ozan Alkan avatar
    9 posts
    Member since:
    Jul 2009

    Posted 02 Jul 2010 Link to this post

    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
    '=======================================================

  11. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 02 Jul 2010 Link to this post

    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
  12. Sheraz Naseeb
    Sheraz Naseeb avatar
    22 posts
    Member since:
    Mar 2010

    Posted 29 Sep 2010 Link to this post

    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
  13. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 30 Sep 2010 Link to this post

    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
  14. Sheraz Naseeb
    Sheraz Naseeb avatar
    22 posts
    Member since:
    Mar 2010

    Posted 30 Sep 2010 Link to this post

    Thanks Emanuel,

    It works...
  15. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 26 Oct 2010 Link to this post

    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?
  16. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 27 Oct 2010 Link to this post

    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
  17. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 27 Oct 2010 Link to this post

    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!
  18. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 27 Oct 2010 Link to this post

    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
  19. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 27 Oct 2010 Link to this post

    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.
  20. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 27 Oct 2010 Link to this post

    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!
  21. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 27 Oct 2010 Link to this post

    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
  22. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 27 Oct 2010 Link to this post

    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?

  23. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 27 Oct 2010 Link to this post

    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
  24. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 27 Oct 2010 Link to this post

    Forgot to mention, you don't have to call calendar.Visible = false in order for it to close.
  25. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 27 Oct 2010 Link to this post

    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!
  26. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 27 Oct 2010 Link to this post

    Hello again,

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

    Best Regards,
    Emanuel Varga
  27. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 27 Oct 2010 Link to this post

    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>)
  28. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 27 Oct 2010 Link to this post

    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
  29. Answer
    Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 27 Oct 2010 Link to this post

    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!
  30. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 27 Oct 2010 Link to this post

    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
  31. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 27 Oct 2010 Link to this post

    Yes. And I have been seeing your name there quite a bit as well. :-)
Back to Top
UI for WinForms is Visual Studio 2017 Ready