date[inc] = [0] = "01/01/2011"
dateTimePicker1.Value = {01/01/2011 00:00:00}
The if condition is never fulfilled when changing a secondary datetimepicker. The first datetimepicker has to be changed once before this code will work. This code is triggered by a ValueChanged in both cases.
Any ideas?
Edit:
int start;
int inc = 0;
while (true)
{
inc++;
if (Convert.ToString(dateTimePicker1.Value.ToShortDateString()) == date[inc])
{
start = inc;
inc = 0;
break;
}
}
=/=
int start;
int inc = 0;
while (true)
{
if (Convert.ToString(dateTimePicker1.Value.ToShortDateString()) == date[inc])
{
start = inc;
inc = 0;
break;
}
inc++;
}
Still very helpful comments, thanks everyone. Obviously was missing the first date because of an increment, causing an infinite loop.
Try to compare like this
OR
Also you can do
.Trim()ondate[inc]it might help you.EDIT
When you compare
stringthings to look for.Trim()string.Equals(string1, string2, StringComparison.InvariantCultureIgnoreCase)Hope this works for you.