private void dataGridgroup_CellContentClick(object sender, DataGridViewCellEventArgs e) { dataGridgroup.Rows[e.RowIndex].ReadOnly = true; int noOfRows = dataGridgroup.RowCount; if (e.ColumnIndex == 2 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) // when click on add button { groupId = Convert.ToInt32(dataGridgroup.Rows[e.RowIndex].Cells[0].Value); this.Hide(); EvaluationGroup create = new EvaluationGroup(); create.ShowDialog(); this.Close(); } if (e.ColumnIndex == 3 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) // when click on view button { groupId = Convert.ToInt32(dataGridgroup.Rows[e.RowIndex].Cells[0].Value); this.Hide(); ShowMembers create = new ShowMembers(); create.ShowDialog(); this.Close(); } else { } }
private void groupEvaluationDatagrid_CellContentClick(object sender, DataGridViewCellEventArgs e) { groupEvaluationDatagrid.Rows[e.RowIndex].ReadOnly = true; int noOfRows = groupEvaluationDatagrid.RowCount; if (e.ColumnIndex == 7 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) { groupId = Convert.ToInt32(groupEvaluationDatagrid.Rows[e.RowIndex].Cells[0].Value); evaluationId = Convert.ToInt32(groupEvaluationDatagrid.Rows[e.RowIndex].Cells[1].Value); this.Hide(); EvaluationGroup st = new EvaluationGroup(); st.ShowDialog(); this.Close(); } if (e.ColumnIndex == 8 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) // when click on del button { DialogResult dialogResult = MessageBox.Show("Are you sure that you want to delete it?", "Confirmation", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { SqlConnection con = new SqlConnection(conURL); // connection open con.Open(); string cmdText = "DELETE FROM GroupEvaluation WHERE GroupId = @GroupId AND EvaluationId =@EvaluationId "; SqlCommand c = new SqlCommand(cmdText, con); int gId = Convert.ToInt32(groupEvaluationDatagrid.Rows[e.RowIndex].Cells[0].Value); int eid = Convert.ToInt32(groupEvaluationDatagrid.Rows[e.RowIndex].Cells[1].Value); c.Parameters.Add(new SqlParameter("@GroupId", gId)); c.Parameters.Add(new SqlParameter("@EvaluationId", eid)); // execute it c.ExecuteNonQuery(); // connection closed con.Close(); dataGridgroup.DataSource = null; dataGridgroup.Rows.Clear(); dataGridgroup.Columns.Clear(); groupEvaluationDatagrid.DataSource = null; groupEvaluationDatagrid.Rows.Clear(); groupEvaluationDatagrid.Columns.Clear(); update(); MessageBox.Show("Successfully Deleted!!"); } else if (dialogResult == DialogResult.No) { //do something else } } }