private void ComboBox_Semester_SelectedIndexChanged(object sender, EventArgs e) { Listbox_Available.Items.Clear(); var source = course.GetCourseBySemester(ComboBox_Semester.Text.Trim()); foreach (DataRow row in source.Rows) { Listbox_Available.Items.Add(row["label"]); } for (int i = 0; i < Listbox_Available.Items.Count; i++) { for (int j = 0; j < ListBoxCourse.Items.Count; j++) { if ( Listbox_Available.GetItemText((int)ListBoxCourse.Items[i]) == ListBoxCourse.GetItemText((int)ListBoxCourse.Items[j]) ) { Listbox_Available.Items.Remove(ListBoxCourse.Items[j]); } } } }
public void LoadListBox() { ListBoxCourse.Items.Clear(); if (ComboBox_Student.Text.Length == 0) { return; } var source = student.GetSelectedCourses(Convert.ToInt32(ComboBox_Student.Text.Trim())); foreach (DataRow row in source.Rows) { ListBoxCourse.Items.Add(row["label"]); } Listbox_Available.Items.Clear(); source = course.GetCourseBySemester(ComboBox_Student.Text.Trim()); foreach (DataRow row in source.Rows) { Listbox_Available.Items.Add(row["label"]); } for (int i = 0; i < Listbox_Available.Items.Count; i++) { for (int j = 0; j < ListBoxCourse.Items.Count; j++) { try { if (Listbox_Available.GetItemText((int)Listbox_Available.Items[i]) == ListBoxCourse.GetItemText((int)ListBoxCourse.Items[j])) { Listbox_Available.Items.Remove(ListBoxCourse.Items[j]); } } catch (Exception) { continue; } } } }