How can I make a DateTimePicker display an empty string?

后端 未结 8 693
不知归路
不知归路 2020-11-28 08:12

I would like to be able to display a DateTimePicker that has a default value of nothing, i.e. no date.

For example, I have a start date dtTaskStar

8条回答
  •  没有蜡笔的小新
    2020-11-28 09:01

    Listen , Make Following changes in your code if you want to show empty datetimepicker and get null when no date is selected by user, else save date.

    1. Set datetimepicker FORMAT property to custom.
    2. set CUSTOM FORMAT property to empty string " ".
    3. set its TAG to 0 by default.
    4. Register Event for datetimepicker VALUECHANGED.

    Now real work starts

    if user will interact with datetimepicker its VALUECHANGED event will be called and there set its TAG property to 1.

    Final Step

    Now when saving, check if its TAG is zero, then save NULL date else if TAG is 1 then pick and save Datetime picker value.

    It Works like a charm.

    Now if you want its value be changed back to empty by user interaction, then add checkbox and show text "Clear" with this checkbox. if user wants to clear date, simply again set its CUSTOM FORMAT property to empty string " ", and set its TAG back to 0. Thats it..

提交回复
热议问题