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;
}
}
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!