的DateTimePicker显示显示其实际价值的今天的日期,而不是而不是、实际、日期、价值

2023-09-05 00:13:39 作者:有点上瘾

我们有几个DateTimePickers的一个自定义用户控件,在窗体上。他们是可见的,但没有启用(仅用于显示)。当用户控件加载时,DateTimePickers从一个DataRow是来自一个数据集存储单个记录从SQL Server存储过程返回指定的值。

有一个不一致的行为,其中,用户有时会看到,被分配到的DateTimePicker日期今天的日期来代替。它似乎没有也罢我给我想要的。价值属性或属性。文日期:

  txtstart.Value =(DateTime的)博士[Group_Start_Date];
txtend.Text =博士[Term_Date]的ToString()。
 

我想到两个语句上面的是,一个使用Value属性是比较合适的。但是,在这两种情况下,今天的日期的是,分别在数据库中的值显示给用户不管。在txtstart.Value的情况下,Visual Studio中显示我的价值分配预期。那么为什么不显示该日期给用户,而不是今天的日期?

解决方案

我结束了与AB诺兰的建议将。后面的禁用的DateTimePicker的理由是从来没有我清楚,所以回到2009/10/23,而不是继续用我只是显示我想在文本框代替。

日期控制大惊小怪jQuery的datetimepicker无法选择日期

We have a couple of DateTimePickers on a custom UserControl, on a Form. They are visible, but not enabled (for display purposes only). When the UserControl is loading, the DateTimePickers are assigned values from a DataRow that came from a DataSet which stores a single record returned from a SQL Server stored procedure.

There is an inconsistent behavior in which the users sometimes see today's date instead of the date that was assigned to the DateTimePicker. It doesn't seem to matter whether I assign the date I want to the .Value property or the .Text property:

txtstart.Value = (DateTime) dr["Group_Start_Date"];
txtend.Text = dr["Term_Date"].ToString();

I expect that of the two statements above, the one using the Value property is more appropriate. But, in both cases, today's date is displayed to the user regardless of the values that were in the database. In the case of txtstart.Value, Visual Studio shows me that the value was assigned as expected. So why isn't it displaying that date to the user instead of today's date?

解决方案

I ended up going with AB Nolan's suggestion. The reasoning behind a disabled DateTimePicker was never clear to me, so back on 10/23/2009, rather than continue fussing with the control I just displayed the dates I wanted in TextBoxes instead.