コード例 #1
0
        //Editing and deleting data from product list table
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string colName = dataGridView1.Columns[e.ColumnIndex].Name;

            if (colName == "Edit")
            {
                frmProduct frm = new frmProduct(this);
                frm.btnSave.Enabled   = false;
                frm.btnUpdate.Enabled = true;
                frm.txtPCode.Text     = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                frm.txtBarcode.Text   = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                frm.txtDesc.Text      = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
                frm.txtPrice.Text     = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
                frm.comboBox1.Text    = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
                frm.comboBox2.Text    = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
                frm.ShowDialog();
            }
            else if (colName == "Delete")
            {
                if (MessageBox.Show("Are you sure you want to delete this record?", eTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    connString.Open();
                    cm = new SqlCommand("delete from tblProduct where proCode like '" + dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() + "'", connString);
                    cm.ExecuteNonQuery();
                    connString.Close();
                    MessageBox.Show("Brand deleted successfuly", eTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    loadRecords();
                }
            }
        }
コード例 #2
0
        private void pictureBox2_Click_1(object sender, EventArgs e)
        {
            frmProduct frm = new frmProduct(this);

            frm.btnSave.Enabled   = true;
            frm.btnUpdate.Enabled = false;
            frm.ShowDialog();
        }