Reputation: 3181
I have a radDateTimePicker that should have a null value when the form starts, I'm setting it like this:
radDateTimePicker1.NullDate = new DateTime(1900, 1, 1);
this.radDateTimePicker1.DateTimePickerElement.SetToNullValue();
on button click I check whether the user has changed the date from 1/1/1900 if it still 1/1/1900 I'll discard the change, but the problem is when the user opens the picker it opens to that date 1/1/1900 and it is not handy to make user loop through all these years to get to 2013, so I changed the nullDate to 1/1/2013 so the picker will open in 1/1/2013 but what if this date is the user target date and I discarded it.
In short, I need a null value that wont make the picker opens in 1900 and will let me know that the user has not changed a value so I can discard this value !?
Upvotes: 0
Views: 1076
Reputation: 3120
If I understand correctly, your requirement is to show the date time picker with null value when the application starts. If so, just call the SetToNull method OnLoad:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
radDateTimePicker1.SetToNullValue();
}
Calling the above method will set the NullableValue to null and the editable part of the control will not display nothing (just the NullText of such is set and the control looses focus). Opening the control will default to the today's date.
Upvotes: 1
Reputation: 62012
Consider using the ShowCheckBox
functionality of the picker:
radDateTimePicker1.ShowCheckBox = true;
When reading the value, you can then say:
var readInput = radDateTimePicker1.Checked
? radDateTimePicker1.Value : (DateTime?)null;
Upvotes: 0
Reputation: 109852
I would use a simple class to encapsulate all the data that the user can change, and initialise it to the "starting" data for the form.
Then when the user clicks "OK" for the form, collect the current form data into another instance of that simple class.
Then compare the two classes to see if anything changed, and respond appropriately.
I think this is more flexible and extendible than messing around with individual controls. It means that you can populate all your data controls with either the current user-chosen settings, or with default values if the user hasn't yet selected anything, and it will work either way.
Upvotes: 0