DateTimePicker - Clear Text

5 posts, 0 answers
  1. Doug
    Doug avatar
    50 posts
    Member since:
    Jul 2012

    Posted 04 Jan 2013 Link to this post

    I've read many forum entries regarding clearing the text in a DateTimePicker and also showing the Clear and Today buttons.  So I have tested with this code and made things work well enough so far.

    public Form1()
     {
         InitializeComponent();
         RadDateTimePickerCalendar datePickerCalendarBehavior = (this.dtpTest.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar);
         RadCalendar calendar = datePickerCalendarBehavior.Calendar;
         calendar.ShowFooter = true;
         calendar.CalendarElement.CalendarStatusElement.Text = "";
         datePickerCalendarBehavior.DropDownMinSize = new Size(250, 250);
         dtpTest.NullableValue = null;
         dtpTest.NullDate = System.Convert.ToDateTime("01/01/0001");
         dtpTest.NullText = " ";
     }
     private void dtpTest_KeyDown(object sender, KeyEventArgs e)
     {
         if (e.KeyData == Keys.Delete)
         {
             dtpTest.SetToNullValue();
             e.Handled = true;
         }
     }

    The text clears when I press the Delete key and the calendar shows the Clear and Today buttons.

    1. What's the Clear button supposed to do?  Am I supposed to handle the event myself or is it supposed to clear out the date?  I don't see anything happening when I click that, even without handling the KeyDown event.

    2. From the older forum posts I've read, I think that maybe there is a way to use the properties of the RadDateTimePicker to clear the text without having to extend the control and add a KeyDown handler and other property settings.  Is there some way to do that via the properties of the control now?

    Thank you,
    Gary



  2. y2kdis
    y2kdis avatar
    9 posts
    Member since:
    Nov 2012

    Posted 07 Jan 2013 Link to this post

    For q #1:

    InitializeComponent();
    RadDateTimePickerCalendar datePickerCalendarBehavior = (this.dtpTest.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar);
    RadCalendar calendar = datePickerCalendarBehavior.Calendar;
    calendar.ShowFooter = true;
    calendar.CalendarElement.CalendarStatusElement.Text = "";
    datePickerCalendarBehavior.DropDownMinSize = new Size(250, 250);
    dtpTest.NullableValue = null;
    dtpTest.NullDate = System.Convert.ToDateTime("01/01/0001");
    dtpTest.NullText = " ";
    calendar.ClearButton.Click += delegate
    {
        dtpTest.SetToNullValue();
    };


    For q #2, I don't think there's a way to do it via the Property Manager as the processing involved in the click event of any button in the footer may vary across apps, but I may be wrong. 
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 09 Jan 2013 Link to this post

    Hi guys,

    Thank you both for writing.

    1. The clear buttons clears the selected cells in the calendar, when multiple selection is enabled and multiple dates are selected.

    2. Currently, there is no built in functionality to clear the control text and value when the delete key is pressed and the right way to that that is to call the control's SetToNullValue method when the Delete key is pressed. 

    I hope this helps.

    Greetings,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  5. Denis Cilliers
    Denis Cilliers avatar
    62 posts
    Member since:
    Jan 2004

    Posted 23 Jul 2013 Link to this post

    How would we clear the control then in VB.net?
  6. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 26 Jul 2013 Link to this post

    Hi Denis,

    If you want to set null value to the control, hence show its null text when not focused, you can use the SetToNullValue method of RadDateTimePicker. 

    For conversion between C# and VB you can use our free online converter at: http://converter.telerik.com/.

    I hope this helps.
     

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready