问题描述
我正在使用VS2013在c#中编写桌面应用程序。在我看来,我得到了一个荒谬的错误,这个错误是无法产生的。我在代码中的某处设置DateTimePicker的MinDate和MaxDate属性:
I am writing a desktop application in c# using VS2013. I am getting an absurd error that has not to be produced, in my opinion. I am setting a DateTimePicker's MinDate and MaxDate properties somewhere in the code in such way:
DateTime minDate = DateTime.Parse(...);
DateTime maxDate = DateTime.Parse(...);
...
if (maxDate < dtpManuelFirst.MinDate)
{
dtpManuelFirst.MinDate = minDate;
dtpManuelFirst.MaxDate = maxDate;
}
else
{
if (minDate > dtpManuelFirst.MaxDate)
{
dtpManuelFirst.MaxDate = maxDate;
dtpManuelFirst.MinDate = minDate;
}
else
{
dtpManuelFirst.MinDate = minDate;
dtpManuelFirst.MaxDate = maxDate;
}
}
最初我知道 minDate 值始终小于 maxDate 价值。这是绝对的。当 minDate 大于 dtpManuelFirst.MaxDate 时,就像第二个if条件一样,它会更新 MaxDate 属性而没有问题,而我得到错误value对于 MinDate 无效。 MinDate 必须小于 MaxDate 。更新 MinDate 属性。这是荒谬的,因为我已经检查了这些条件。此外,当我检查调试模式时,这些值不支持错误。假设 dtpManuelFirst.Mindate 25.01.2014 和 dtpManuelFirst.MaxDate 27.01.2014 。假设 minDate 18.04.2014 且 maxDate 19.04.2014 。然后它将转到第二个if语句并输入它。首先更新 MaxDate 属性不会产生错误。现在我们 dtpManuelFirst.MaxDate 19.04.2014 和 dtpManuelFirst.MinDate 25.01.2014 。在这些条件下,它会将 minDate 值赋值给 MinDate 属性时生成错误。任何帮助都会很棒!
Very initially i know that minDate value is always less than maxDate value. This is absolute. When minDate is bigger than dtpManuelFirst.MaxDate like the second if condition, it updates the MaxDate property with no problem whereas i get the error "value is not valid for MinDate. MinDate must be less than MaxDate." on updating the MinDate property. It is ridiculous since i am already checking these conditions. In addition, the values are not supporting the error when i check in debug mode. Let say dtpManuelFirst.Mindate is 25.01.2014 and dtpManuelFirst.MaxDate is 27.01.2014. Let say minDate is 18.04.2014 and maxDate is 19.04.2014. then it will be going to the second if statement and enter in it. Updating firstly MaxDate property will not produce an error. Now we have dtpManuelFirst.MaxDate is 19.04.2014 and dtpManuelFirst.MinDate is 25.01.2014. Under these conditions it generates the error while assignign minDate value to MinDate property. Any help would be great!
推荐答案
else
{
dtpManuelFirst.MinDate = minDate;
dtpManuelFirst.MaxDate = maxDate;
}
成为:
Becomes:
else
{
dtpManuelFirst.MaxDate = maxDate;
dtpManuelFirst.MinDate = minDate;
}
在您的版本中,当您尝试将Mindate设置为18.04.2014时,MaxDate当前为27.01.2014 - 因此该值不在该范围内。设置最大值应该解决问题。
In your version, the MaxDate is currently 27.01.2014 when you try to set the Mindate to 18.04.2014 - so the mindate is outside the range. Setting the max first should solve teh problem.
这篇关于荒谬的MinDate MaxDate分配错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!