//Method for edit and delete oparetion for button click private void tblSub_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { //Edit Record Button form.clear(); //clear form data in addlecturer form //Add table value to update form form.id = tblSub.Rows[e.RowIndex].Cells[2].Value.ToString(); form.subname = tblSub.Rows[e.RowIndex].Cells[3].Value.ToString(); form.subcode = tblSub.Rows[e.RowIndex].Cells[4].Value.ToString(); form.offeredyear = tblSub.Rows[e.RowIndex].Cells[5].Value.ToString(); form.offeredsem = tblSub.Rows[e.RowIndex].Cells[6].Value.ToString(); form.lechr = tblSub.Rows[e.RowIndex].Cells[7].Value.ToString(); form.tutehr = tblSub.Rows[e.RowIndex].Cells[8].Value.ToString(); form.labhr = tblSub.Rows[e.RowIndex].Cells[9].Value.ToString(); form.evehr = tblSub.Rows[e.RowIndex].Cells[10].Value.ToString(); form.updateSubInfo(); //Call updateLecInfo methord to change form spesific content form.ShowDialog(); DataTable dt = s.selectSubject(); tblSub.DataSource = dt; return; } if (e.ColumnIndex == 1) { //Delete Record Button if (MessageBox.Show("Are you sure?\n\nDo you really want to delete this record?\nThis process cannot be undone!", "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop) == DialogResult.Yes) { //Pass the lecturer id to deleteLecturer method s.deleteSubject(tblSub.Rows[e.RowIndex].Cells[2].Value.ToString()); //load lecturer table to gridview after deleting the row DataTable dt = s.selectSubject(); tblSub.DataSource = dt; } return; } }