private void deleteCourse_button_Click(object sender, EventArgs e) { if (listView.SelectedItems.Count == 0) { MessageBox.Show("No course was selected."); return; } else if (listView.SelectedItems.Count > 1) { MessageBox.Show("Choose only one course to delete at the time."); return; } HeadOfDepartmentSQL headOfDepartmentSql = new HeadOfDepartmentSQL(this.sqlConnection); int courseID; try { courseID = Convert.ToInt16(this.listView.SelectedItems[0].SubItems[0].Text); } catch (Exception errorMsg) { MessageBox.Show(errorMsg.Message); return; } headOfDepartmentSql.DeleteCourse(courseID); CourseSQL.LoadCoursesToListView(ref this.listView); }