I've got a few RadDateTimePickers which are all bound to various data sources. Some of them have a null value, some have values, which all display fine - however the issue I am having is that when you click the field to select a date, the default date that is selected is from when I added the control to the form.
This should be today's date, however the value of the field should remain null until the user has clicked a date. They do need to be able to select a date in the past/future though as well.
I'm using the latest version of Telerik UI for WinForms on a VB.net project.
Any help would be much appreciated.
Thanks, Shane
7 Answers, 1 is accepted
Thank you for writing.
You can set the value of the editor to null by calling its SetToNullValue: Set Null or Empty Value.
The control also defines MinDate and MaxDate properties with which you would be able to set range with allowed dates. Please check my code snippet below:
Public
Sub
New
()
InitializeComponent()
Me
.radDateTimePicker1.NullText =
"No date selected"
Me
.radDateTimePicker1.NullableValue =
Nothing
Me
.radDateTimePicker1.SetToNullValue()
Me
.radDateTimePicker1.MinDate = DateTime.Now.AddDays(-20)
Me
.radDateTimePicker1.MaxDate = DateTime.Now.AddDays(20)
End
Sub
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik

Shane, did you solve this issue. Hristo seems to have glossed over what you actually asked and posted about how to use the NullableValue property. I now have the same issue as you described...
A RadDateTimePicker is bound to a database date column that can have a Null value. Properties as displayed in VS2015:
DataBindings.Value = [BindingSource - ColumnName]
NullText = "No date selected"
Text = [the date I added the control to the form]
Value = [the date/time I added the control to the form]
When run and the database value is Null, the control correctly displays "No date selected". When the user clicks the dropdown to choose a date from the calendar, the default date is the date the control was added to the form.
What I need, and I think you also wanted, is the calendar by default (when the underlying value was previously Null), to display the current date and not the date when the control was added to the form at design-time.
Is there a way at run-time to set this default date?
Nick.
Thank you for clarifying the scenario.
When you add a RadDateTimePicker from the toolbox its Text and Value are serialized. Setting the value property at the end also updates the selected dates of the calendar.
In this type of scenario, it is appropriate to set the FocusedDate property to the required date this way have it displayed in the calendar drop down:
this
.radDateTimePicker1.DateTimePickerElement.Calendar.FocusedDate = DateTime.Now;
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik by Progress

Hello Hristo. Thanks for the reply.
Setting DateTimePickerElement.Calendar.FocusedDate=Now didn't change anything. The control still shows the date it was added to the form. According to the radCalendar properties page setting FocusedDate should do exactly what's required. Sadly, as implemented as part of radDateTimePicker it doesn't appear to work.
I also looked at DateTimePickerElement.Calendar.RemoveFocusedDate. According to the documentation, it should remove the focused date and change the current view to today. That did remove the highlighted day, but kept the same original month displayed, not the current month. That happened even if I set FocusedDate straight afterwards.
Nick.
Thank you for writing.
I performed some testing with the following setup and on my end, the FocusedDate is correctly displayed in the calendar. Can you please check how it runs on your end?
public
partial
class
Form1 : Form
{
private
BindingList<DateObject> data;
public
Form1()
{
InitializeComponent();
data =
new
BindingList<DateObject>();
data.Add(
new
DateObject(
null
));
this
.radDateTimePicker1.DataBindings.Add(
new
Binding(
"NullableValue"
,
this
.data,
"Date"
,
true
, DataSourceUpdateMode.OnPropertyChanged));
this
.radDateTimePicker1.NullText =
"No date selected"
;
this
.radDateTimePicker1.DateTimePickerElement.Calendar.FocusedDate = DateTime.Now;
}
public
class
DateObject
{
private
DateTime? date;
public
DateObject(DateTime? date)
{
this
.date = date;
}
public
DateTime? Date
{
get
{
return
date; }
set
{ date = value; }
}
}
}
In case you keep experiencing the issue please open a support ticket and send us your project.
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik by Progress

Hello Hristo.
I finally solved this by using these two lines whenever I load a form with a RadDateTimePicker control.
rdtpSomeDate.DateTimePickerElement.Calendar.RemoveFocusedDate(True)
rdtpSomeDate.DateTimePickerElement.Calendar.FocusedDate = DateTime.Now
Nick.
Thank you for writing back.
I am glad that you have managed to achieve the desired result. Thank you also for sharing your solution with the community.
Please let me know if you need further assistance.
Regards,
Hristo
Telerik by Progress