private void dataGridproject_CellContentClick(object sender, DataGridViewCellEventArgs e) { dataGridproject.Rows[e.RowIndex].ReadOnly = true; int noOfRows = dataGridproject.RowCount; if (e.ColumnIndex == 2 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) // when click on assign button { projectID = Convert.ToInt32(dataGridproject.Rows[e.RowIndex].Cells[0].Value); this.Hide(); AssignAdvisor create = new AssignAdvisor(); create.ShowDialog(); this.Close(); } else { } }
private void ProjectAdvisorDatagrid_CellContentClick(object sender, DataGridViewCellEventArgs e) { ProjectAdvisorDatagrid.Rows[e.RowIndex].ReadOnly = true; int noOfRows = ProjectAdvisorDatagrid.RowCount; if (e.ColumnIndex == 5 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) // when click on update { projectID = Convert.ToInt32(ProjectAdvisorDatagrid.Rows[e.RowIndex].Cells[0].Value); AdvisorID = Convert.ToInt32(ProjectAdvisorDatagrid.Rows[e.RowIndex].Cells[1].Value); this.Hide(); AssignAdvisor st = new AssignAdvisor(); st.ShowDialog(); this.Close(); } if (e.ColumnIndex == 6 && 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 opens try { con.Open(); } catch (Exception) { MessageBox.Show("error"); } string cmdText = "DELETE FROM ProjectAdvisor WHERE AdvisorId = @AdvisorId AND ProjectId =@ProjectId "; SqlCommand c = new SqlCommand(cmdText, con); int pId = Convert.ToInt32(ProjectAdvisorDatagrid.Rows[e.RowIndex].Cells[0].Value); int Aid = Convert.ToInt32(ProjectAdvisorDatagrid.Rows[e.RowIndex].Cells[1].Value); c.Parameters.Add(new SqlParameter("@AdvisorId", Aid)); c.Parameters.Add(new SqlParameter("@ProjectId", pId)); // execute it c.ExecuteNonQuery(); // connection closed con.Close(); ProjectAdvisorDatagrid.DataSource = null; ProjectAdvisorDatagrid.Rows.Clear(); ProjectAdvisorDatagrid.Columns.Clear(); dataGridproject.DataSource = null; dataGridproject.Rows.Clear(); dataGridproject.Columns.Clear(); update(); MessageBox.Show("Successfully Deleted!!"); } else if (dialogResult == DialogResult.No) { //do something else } } }