private void btnDelete_Click(object sender, EventArgs e) { try { if (lstMatchingStudents.SelectedIndex > -1) { if (MessageBox.Show("Are you wure you want to delete the current record?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } StudentBL studentBL = new StudentBL(); if (studentBL.Delete_Student(lstMatchingStudents.SelectedValue.ToString())) { MessageBox.Show("Student Deleted!"); ResetForm(); } if (studentBL.Errors.Count != 0) { string msg = ""; foreach (ValidationError error in studentBL.Errors) { msg += error.Description + Environment.NewLine; } MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Please Select Student in the list box", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }