private void SetButtonColor() { List<String> appointmentDates = new List<String>(); appointmentDates.AddRange(appointmentService.getAppointmentsByDocAndDate(SelectedDate, DoctorId)); if (appointmentDates.Count<1) { for (int i = 0; i < buttons.Count; i++) { buttons[i].BackColor = System.Drawing.Color.Green; } } else { for (int i = 0; i < buttons.Count; i++) { int e = 0; Boolean found = false; while (e < appointmentDates.Count && found == false) { if (appointmentDates[e].Equals(buttons[i].Text)) { buttons[i].BackColor = System.Drawing.Color.Red; found = true; } else { buttons[i].BackColor = System.Drawing.Color.Green; e++; } } } } }