public Department_manager_remove_course() { InitializeComponent(); DBC New_Conn_To_DB = new DBC(); List <String> All_Course_id = New_Conn_To_DB.Get_All_CoursesIDs(); List <String> All_Course_with_open_constraints = New_Conn_To_DB.Get_Course_ID_Of_constraints(); bool flag_course_cant_remove; for (int i = 0; i < All_Course_id.Count; i++) { flag_course_cant_remove = false; for (int j = 0; j < All_Course_with_open_constraints.Count; j++) { if (All_Course_id[i] == All_Course_with_open_constraints[j]) { // course id is in constraint listBox.Items.Add(All_Course_id[i] + " -- " + New_Conn_To_DB.Get_Course_Name_From_Course_ID(All_Course_id[i]).Replace(" ", "").Replace("_", " ")); flag_course_cant_remove = true; break; } } if (flag_course_cant_remove == false) { //course not in constraint comboBox1.Items.Add(All_Course_id[i] + " -- " + New_Conn_To_DB.Get_Course_Name_From_Course_ID(All_Course_id[i]).Replace(" ", "").Replace("_", " ")); } } }