how to identity if user clicked on a date in DateTimePicker calendar

前端 未结 4 1940
心在旅途
心在旅途 2020-12-21 17:55

I don\'t want the date to change when user clicks out of the calender without clicking on a date. The problem is One Date is always selected when the datepickercalendar open

4条回答
  •  礼貌的吻别
    2020-12-21 18:12

    There is already at least 1 DateTimePicker control on CodeProject which allows for a Nullable Date. But there is a simpler method than that.

    In design, set the ShowCheckBox to True. Then when the form loads or you are resetting fields, set Checked to False. This makes the DTP look disabled which is a little unfortunate, but when the user opens the DTP, the Checkbox is automatically checked. So, all you need to do to see if they picked a date, is to evaluate the Checked property. The disabled appearance ends up indicating that the value doesnt really count, if they should happen to uncheck it after selecting a valid date.

    If you use the smaller version (ShowUpDown), the control is disabled until they first click the checkbox, then select a field to spin thru. You will still get a value changed event for each change of each field, but thats how it is supposed to work. The control always has a valid date value so you dont have to check against Nothing etc.

提交回复
热议问题