Databound DateTimePicker 引发验证错误
我有一个数据绑定 DateTimePicker:
dateDateTimePicker.DataBindings.Add(new Binding("Value", paymentBindingSource, "Date", true);
paymentBindingSource.DataSource = payment;
payment 是实体框架对象。
payment.Date 包含有效的日期时间。显示表单时,dateDateTimePicker 包含正确的值,但旁边会显示 ErrorProvider,提示
“Value of '01.01.0001 00:00:00' 对于 'Value' 无效。”
当我将 dateDateTimePicker 值更改为任何值时消失。
I have a databound DateTimePicker:
dateDateTimePicker.DataBindings.Add(new Binding("Value", paymentBindingSource, "Date", true);
paymentBindingSource.DataSource = payment;
payment
is Entity Framework object. payment.Date
contains valid DateTime. When form is shown, dateDateTimePicker contains correct value, but an ErrorProvider is shown next to it, saying "Value of '01.01.0001 00:00:00' is not valid for 'Value'."
It disappears when I change dateDateTimePicker value to anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试颠倒这两行代码。第一行可能正在查找数据源,此时该数据源为空。
Try reversing those two lines of code. The first line is probably looking to the data source, which, at that point, is null.
可以看到您的验证码吗?我猜测当您第一次加载表单时会发生验证错误,并且绑定数据的方式不会清除(现有的)验证错误,而当您手动更改值时,则会触发相关代码。
Would it be possible to see your validation code? I am guessing the validation error occurs when you first load the form, and that the way you bind the data does not clear the (existing) validation error, while when you manually change the value, that is triggering the relevant code.