private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { int id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value); if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) { string command = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); if (command.ToLower() == "delete") { try { if (MessageBox.Show("Are you sure to Delete", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var seminar = db.Seminars.Where(ss => ss.Id == id).Include(s => s.AudiencePerSeminars).Include(s => s.PresentersPerSeminars).Include(s => s.RoomStallLocation).FirstOrDefault(); //db.Entry(seminar).State = EntityState.Deleted; db.Seminars.Remove(seminar); db.SaveChanges(); MessageBox.Show("Seminar Successfully deleted"); LoadSeminars(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else if (command.ToLower() == "edit") { AddSeminar addSeminar = new AddSeminar(id); addSeminar.Show(); } } }
private void addSeminarToolStripMenuItem1_Click(object sender, EventArgs e) { AddSeminar frmAddSeminar = new AddSeminar(0); frmAddSeminar.Show(); }