I have 2 foreach loops, my first one is in a method, this method starts when my main form loads, the method is the following:
private void GetDateDay()
{
foreach (DateTimePicker Dater in this.ReminderPanel.Controls.OfType<DateTimePicker>())
{
label1.Text = "true";
DateTime DaterValue = Dater.Value;
DateList.Add(Dater.Value);
}
SundayTotal = DateList.Count(x => x.DayOfWeek == DayOfWeek.Sunday);
MondayTotal = DateList.Count(x => x.DayOfWeek == DayOfWeek.Monday);
TuesdayTotal = DateList.Count(x => x.DayOfWeek == DayOfWeek.Tuesday);
WednesdayTotal = DateList.Count(x => x.DayOfWeek == DayOfWeek.Wednesday);
ThursdayTotal = DateList.Count(x => x.DayOfWeek == DayOfWeek.Thursday);
FridayTotal = DateList.Count(x => x.DayOfWeek == DayOfWeek.Friday);
SaturdayTotal = DateList.Count(x => x.DayOfWeek == DayOfWeek.Saturday);
}
This Method isn´t working, and as you can see, I changed a label.text because I wanted to see when the loop don´t work, and i found that it work but not after the loop because the label dont change its text. My theory, Is that because i Have so much controls in my main form, and my panel´s controls load by code, the method loop returns null, because the method checks before the panels controls load, even if the method is called after the UI Load Method is called.
Panel code:.
TaskUC Task = new TaskUC ();
ReminderPanel.Controls.Add(Task);
(TaskUC Contains The DateTimePicker - so the Panel contains TaskUC which contains the DateTimePicker).