的DateTimePicker默认值:如何避免呢? [英] DateTimePicker Default value: How to avoid it?
本文介绍了的DateTimePicker默认值:如何避免呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
事实:
- 我有2个选项卡一个TabControl,每个选项卡有2个的DateTimePicker
- 在Load事件中,我将所有的DTPS的价值。
- 所有DTPS对真正的设置ShowCheckBoxes并检查虚假设置。
- 当我执行程序,在第一个选项卡的DTPS都OK,但是当我检查第二个选项卡上DTPS,它们显示当前时间,不是我的负载事件中设置的时间。
- I have a TabControl with 2 Tabs, Each tab has 2 DateTimePicker.
- In the Load event, I set the value of all the DTPs.
- All DTPs have ShowCheckBoxes set on true AND Checked set on false.
- When I Execute the program, The DTPs in first tab are OK, but when I check the DTPs on second tab, they show current time, not the time I set on the load event.
为什么出现这种情况?我怎样才能避免呢?
Why this happen? How can I avoid it?
推荐答案
我的丑的解决方法这个问题,包括上设置活动选项卡中的DTP的驻留前改变它的值,这样的事情:
My ugly workaround to this issue, consists on set active the tab in which the DTP's reside before changing its values, something like this:
DateTime dat1 = DateTime.Today;
DateTime dat2 = dat1.AddDays(1).AddSeconds(-1);
dtpCreatedStart.Value = dat1;
dtpCreatedEnd.Value = dat2;
tbc.SelectTab(1);
dtpModifiedStart.Value = dat1;
dtpModifiedEnd.Value = dat2;
tbc.SelectTab(0);
这篇关于的DateTimePicker默认值:如何避免呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文