我怎样才能让一个DateTimePicker显示一个空字符串? [英] How can I make a DateTimePicker display an empty string?
问题描述
我想是能够显示<$ C $ C>的DateTimePicker ,有没什么默认值,即没有日期。
I would like to be able to display a DateTimePicker
that has a default value of nothing, i.e. no date.
例如,我有一个起始日期 dtTaskStart
和结束日期 dtTaskEnd
的任务,但终日期不知道,并且未填充最初
For example, I have a start date dtTaskStart
and an end date dtTaskEnd
for a task, but the end date is not known, and not populated initially.
我已经指定了 YYYY-MM-DD
自定义格式为对照组。
I have specified a custom format of yyyy-MM-dd
for both controls.
将该值设置为空
,或在运行时为空字符串会导致错误,所以我怎么能做到这一点?
Setting the value to null
, or an empty string at runtime causes an error, so how can I accomplish this?
我用一个复选框来控制这一领域的实现已经考虑,但仍有显示一个初始值的问题。
I have considered using a checkbox to control the enabling of this field, but there is still the issue of displaying an initial value..
编辑:的
可以说,问题的重复的DateTimePicker空值(.NET),但我找到了解决方案我的问题是不是这个问题的解决方案,所以我觉得应该留在这里为他人找到。
Arguably a duplicate of the question DateTimePicker Null Value (.NET), but the solution I found for my problem is not a solution for that question, so I think it should remain here for others to find..
推荐答案
通过使用 CustomFormat
属性,使用复选框进行模糊值 cbEnableEndDate
作为标志,以指示其他code是否应忽略的值:
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
这篇关于我怎样才能让一个DateTimePicker显示一个空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!