try { string colNamee = dataGridView2.Columns[e.RowIndex].Name; if (colNamee == "Edit") { FrmAddProduct frmadd = new FrmAddProduct(this); frmadd.btnSave.Enabled = false; frmadd.btnUpdate.Enabled = true; frmadd.txtID.Text = dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString(); frmadd.txtDescriprion.Text = dataGridView2.Rows[e.RowIndex].Cells[1].Value.ToString(); frmadd.txtPrice.Text = dataGridView2.Rows[e.RowIndex].Cells[4].Value.ToString(); frmadd.txtQty.Text = dataGridView2.Rows[e.RowIndex].Cells[5].Value.ToString(); frmadd.cboBrand.Text = dataGridView2.Rows[e.RowIndex].Cells[2].Value.ToString(); frmadd.cboCategory.Text = dataGridView2.Rows[e.RowIndex].Cells[3].Value.ToString(); frmadd.ShowDialog(); RefreshProduct(); } else if (colNamee == "Delete") { if (MessageBox.Show("Are you sure you want to delete this product record?", "Delete Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { con.Open(); cmd = new MySqlCommand("Delete from tblProduct where Pcode ='" + dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString() + "'", con); cmd.ExecuteNonQuery(); con.Close(); RefreshProduct(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); }
cmd = new MySqlCommand("Delete from tblProduct where Pcode ='" + dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString() + "'", con);
DataGridViewRow currentRow = dataGridView2.Rows[e.RowIndex]; if(currentRow==null) return; //your code here...
if(e.RowIndex==-1) return; //your code here...
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)