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

DateTimePicker - Clear Text

4 Answers 1201 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 04 Jan 2013, 10:47 PM
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



4 Answers, 1 is accepted

Sort by
0
y2kdis
Top achievements
Rank 1
answered on 07 Jan 2013, 07:31 PM
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. 
0
Stefan
Telerik team
answered on 09 Jan 2013, 02:10 PM
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.
0
Denis Cilliers
Top achievements
Rank 1
answered on 23 Jul 2013, 10:12 AM
How would we clear the control then in VB.net?
0
Stefan
Telerik team
answered on 26 Jul 2013, 05:10 AM
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 >>
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Doug
Top achievements
Rank 1
Answers by
y2kdis
Top achievements
Rank 1
Stefan
Telerik team
Denis Cilliers
Top achievements
Rank 1
Share this question
or