每当我启动我的程序时,DateTimePicker会自动显示今天的日期和时间 . 我怎么能阻止这个?我怎么能把它弄空白?
我有一个DOB DateTimePicker . 对于一些用户我不知道他们的DOB,所以我希望DateTimePicker显示null或空字段 .
我认为没有办法允许它为空,但您可以使用ShowCheckBox和Checked属性设置为true . 除了日期下拉列表之外,DateTimePicker还将有一个复选框 . 未选中时禁用日期下拉列表 . 这样,当未选中复选框时,您可以为DOB设置“无值”或null .
设置 DateTimePicker.CustomFormat = " " 确保有空格 . 这将显示为空白区域 .
DateTimePicker.CustomFormat = " "
我用 DataRowView drv = DBBindingSource(DB) . 以及在需要时设置null的控制语句 .
DataRowView drv = DBBindingSource(DB)
if(drv.Row["DOB"] == DBNull.Value) { DateTimePicker.CustomFormat = " "; } else { DateTimePicker.CustomFormat = "dd MMMM yyyy"; }
请参阅Nullable DateTimePicker上的CodeProject文章 . 它来自 DateTimePicker .
DateTimePicker
Use this :
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged DateTimePicker1.Value = DateTimePicker1.Value.Today End Sub
将它的Value属性设置为您想要的日期 .
如果你正在谈论Trent Richardson的datetimepicker,请看一下这个帖子https://stackoverflow.com/a/12645192/551811
基本上,在onClose事件中设置inputbox值 .
$('input.datetime').datetimepicker({ onClose: function (value) { $('input.datetime').val(value); } });
我的解决方案
Public Sub ClearDatePicker(ByVal DatePicker As DateTimePicker) DatePicker.CustomFormat = " " DatePicker.Format = DateTimePickerFormat.Custom End Sub
然后 datetimepicker 将显示为空 .
datetimepicker
7 回答
我认为没有办法允许它为空,但您可以使用ShowCheckBox和Checked属性设置为true . 除了日期下拉列表之外,DateTimePicker还将有一个复选框 . 未选中时禁用日期下拉列表 . 这样,当未选中复选框时,您可以为DOB设置“无值”或null .
设置
DateTimePicker.CustomFormat = " "
确保有空格 . 这将显示为空白区域 .我用
DataRowView drv = DBBindingSource(DB)
. 以及在需要时设置null的控制语句 .请参阅Nullable DateTimePicker上的CodeProject文章 . 它来自
DateTimePicker
.Use this :
将它的Value属性设置为您想要的日期 .
如果你正在谈论Trent Richardson的datetimepicker,请看一下这个帖子https://stackoverflow.com/a/12645192/551811
基本上,在onClose事件中设置inputbox值 .
我的解决方案
然后
datetimepicker
将显示为空 .