WinForm DateTimePicker 忧郁。是我吗?
我希望能够使用 DateTimePicker 控件接受 NULL 日期。
“Checked”属性似乎旨在指定控件是“保留日期”还是现在。但是,当“未选中”时,日期仍然显示,尽管它显示为已禁用。对我来说,这让人分心。如果未选中的复选框的目的是表明没有日期值,为什么文本框中会出现禁用或其他日期值?在我看来,如果未选中该控件,则文本框应该为空,并且当用户真正想要“无值”时看到变暗的日期值会分散注意力。
如果用户打开复选框,那么我希望能够将默认值放入文本框中。
我正在考虑创建一个在 dateTimePicker 控件和 textBox 之间切换的用户控件,但我讨厌经历这个麻烦。
我尝试查看 Telerik 的 DateTimePicker,但试图从该控件中获得像样的空处理功能似乎更糟糕。我很想看到一个工作示例,说明你们认为是一个用户友好的代码示例,其中包含接受空输入的 std MS 或 Telerik DateTimePicker 控件。
我研究过一些开源控件,但每次他们解决一个问题时,都会引入其他问题。
编辑:
请参阅下面我的答案。它似乎工作得很好,现在我只想让它成为每个 DateTimePicker 行为的一部分。
I want to be able to accept a NULL date using the DateTimePicker control.
The "Checked" property appears to be intended to specify whether the control "holds a date" or now. However, when "unchecked", the date still appears, though it appears disabled. To me, this is distracting. If the intent of the unchecked checkbox is to indicate that there is no date value, why is there ANY date value disable or otherwise that appears in the textbox? It seems to me that if the control is unchecked, the textbox should be EMPTY and that seeing a dimmed date value when the user really wants "no value" is distracting.
If the user toggled the checkbox on, then I would like the ability to place a default value into the textbox.
I am considering creating a usercontrol that toggles between a dateTimePicker control and a textBox, but I hate to go through this trouble.
I tried looking a Telerik's DateTimePicker but trying to get decent null handling functionality out of that control seems worse. I'd love to see a working example of what one of you think is a user-friendly code example with either the std MS or Telerik DateTimePicker control that accepts null input.
I've looked at a few opensource controls, but every time they fix one issue, they introduce others.
EDIT:
See my answer below. It seems to work fine, now I just want to make it part of every DateTimePicker's behavior.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我也有同样的问题。好吧,实际上我很聪明,可以理解,但我的用户遇到了问题。
我通过删除复选框并添加 2 个单选按钮来解决。现在看起来像这样:(
使用伪 UI)
当没有值(空)时检查顶部单选按钮,当有值时检查底部单选按钮。我没有隐藏或禁用底部控件,用户似乎也明白。
缺点是,它需要更多的空间。
PS:用户接下来会抱怨的是当组合框具有焦点时使用滚轮。
I had the same problem. Well, actually I'm smart enough to understand, but my users had a problem.
I solved by removing the checkbox, and adding 2 radio buttons. Looks something like this now:
(using pseudo UI)
The top radiobutton is checked when there is no value (null), the bottom one when there is a value. I do not hide, or disable the bottom control, and users seem to understand.
The downside is, that it takes a lot more space.
PS: Next thing users will complain about is using the scroll-wheel when a combo-box has focus.
Klugey,但它似乎完成了工作。如果未选中该复选框,则假定为 NULL 值。
好的,下一个问题...如何将此行为滚动到子类 DateTimePicker 中?我想要做的是捕获“属性”窗口中设置的 Format 和 CustomFormat 属性的原始值。但是,这显然不是这样做的方法。
这是我微弱的尝试:
Klugey, but it seems to get the job done. If the checkbox is not checked, assume a NULL value.
OK, the next question...How do I roll this behavior into a subclassed DateTimePicker? What I want to do is to capture the original values of the Format and CustomFormat properties as set in the Properties window. But, this clearly isn't the way to do it.
Here's my feeble attempt:
我意识到这已经是你最初的问题很多年之后的事了,但这里有一个 Telerik RadDateTimePicker 的子类,它可以满足你的要求:
要获取选择器的值:
I realise this is many years after your initial question but here's a subclass of the Telerik RadDateTimePicker that does what you were asking for:
To get the value of the picker:
想要正确有点棘手。这看起来不错:
A bit tricky to get right. This looked good: