I am trying to check an entered time in a DateTimePicker control and correct it to the closest acceptable value in C#
if (Summer1.Value.TimeOfDay > Summer2.Value.TimeOfDay)
Summer1.Value.TimeOfDay = Summer2.Value.TimeOfDay;
It gives me the following:
Property or indexer ‘System.DateTime.TimeOfDay’ cannot be assigned to
— it is read only
Why does it handle the DateTimePicker object as a system time?
I could not find anything related to Read-Only state of the control in VS 2003.
Summer1.Valueis the property ofDateTimePickerand it has type ofDateTime. This property is assignable.You’re trying to assign
Summer1.Value.TimeOfDay– which is a property ofDateTimeobjectSummer1.Value– and this property does not have setter inDateTimeclass.should work fine but may not give you the desired result.
The closest to your desirable output will be something like