private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { //opening addcourse form AddCategory category = new AddCategory(); //adding value on CourseID Variable.categoryid = dgv.CurrentRow.Cells[2].Value.ToString(); //adding value on course textbox category.txtcategory.Text = dgv.CurrentRow.Cells[4].Value.ToString(); //changing the button text value category.Add_btn.ButtonText = "Edit"; category.ShowDialog(); } else if (e.ColumnIndex == 1) { DataGridViewRow row = this.dgv.Rows[e.RowIndex]; cid = row.Cells["#"].Value.ToString(); DialogResult dr = MessageBox.Show("Are you sure you want to delete this data", "Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); //delete course if (dr == DialogResult.Yes) { if (dbhelper.openConnection()) { string query = "Delete from tblcategory where categoryID = @id"; MySqlCommand cmd = new MySqlCommand(query, dbhelper.getConnection()); cmd.Parameters.AddWithValue("id", cid); cmd.ExecuteNonQuery(); } dbhelper.closeConnection(); MessageBox.Show("Successfully Delete Data!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); //loadcourse load_categorytbl(); } } }
private void Createbtn_Click(object sender, EventArgs e) { AddCategory category = new AddCategory(); category.ShowDialog(); }