private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { //opening addcourse form AddProduct category = new AddProduct(); //adding value on CourseID Variable.productid = dgv.CurrentRow.Cells[2].Value.ToString(); //adding value on course textbox category.cmbcategory.Text = dgv.CurrentRow.Cells[4].Value.ToString(); category.cmbsupplier.Text = dgv.CurrentRow.Cells[5].Value.ToString(); category.txtproductname.Text = dgv.CurrentRow.Cells[6].Value.ToString(); category.txtquantity.Text = dgv.CurrentRow.Cells[8].Value.ToString(); category.txtdescription.Text = dgv.CurrentRow.Cells[7].Value.ToString(); category.txtprize.Text = dgv.CurrentRow.Cells[9].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]; accid = 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 tblproduct where productID = @id"; MySqlCommand cmd = new MySqlCommand(query, dbhelper.getConnection()); cmd.Parameters.AddWithValue("id", accid); cmd.ExecuteNonQuery(); } dbhelper.closeConnection(); MessageBox.Show("Successfully Delete Data!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); //loadcourse load_producttbl(); } } }
private void Createbtn_Click(object sender, EventArgs e) { AddProduct product = new AddProduct(); product.ShowDialog(); }