private void AddToGroup(ControlGroup taskGroup, TaskView taskView) { if (taskGroup.Count == 0) { taskGroup.Add(taskView); // add if list is empty } else { for (int i = taskGroup.Count - 1; i >= 0; i--) { TaskView tv = (TaskView)taskGroup[i]; if (tv.DueDate > taskView.DueDate) { continue; } else { taskGroup.Insert(i + 1, taskView); // add in the middle or end return; } } taskGroup.Insert(0, taskView); // add at the top after all controls are moved down using loop } }