How can I make a DateTimePicker display an empty string?

后端 未结 8 691
不知归路
不知归路 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:02

    Obfuscating the value by using the CustomFormat property, using checkbox cbEnableEndDate as the flag to indicate whether other code should ignore the value:

    If dateTaskEnd > Date.FromOADate(0) Then
        dtTaskEnd.Format = DateTimePickerFormat.Custom
        dtTaskEnd.CustomFormat = "yyyy-MM-dd"
        dtTaskEnd.Value = dateTaskEnd 
        dtTaskEnd.Enabled = True
        cbEnableEndDate.Checked = True
    Else
        dtTaskEnd.Format = DateTimePickerFormat.Custom
        dtTaskEnd.CustomFormat = " "
        dtTaskEnd.Value = Date.FromOADate(0)
        dtTaskEnd.Enabled = False
        cbEnableEndDate.Checked = False
    End If
    

提交回复
热议问题