Exemplo n.º 1
0
        private void dgvStrand_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                id = Convert.ToInt32(dgvStrand.Rows[e.RowIndex].Cells[2].Value.ToString());//for editing criteria

                //pass value to edit mode
                txtStrandName.Text = dgvStrand.Rows[e.RowIndex].Cells[3].Value.ToString(); //Name
                txtDesc.Text       = dgvStrand.Rows[e.RowIndex].Cells[4].Value.ToString(); //Name

                btnAdd.Text = "&Update";                                                   //set button to Update
            }

            else if (e.ColumnIndex == 1)
            {
                string message = "Do you want to delete this record?";
                string title   = "Enrollment System";

                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result  = MessageBox.Show(message, title, buttons, MessageBoxIcon.Warning);

                if (result == DialogResult.Yes)
                {
                    strand.Id = Convert.ToInt32(dgvStrand.Rows[e.RowIndex].Cells[2].Value.ToString());//for editing criteria
                    strand.Delete();

                    strand.LoadDataTable(dgvStrand);
                }
                else
                {
                    return;
                }
            }
        }
Exemplo n.º 2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DialogResult ans = MessageBox.Show("Are you sure you want to delete this record ", "System message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (ans.Equals(DialogResult.Yes))
            {
                //get id
                strand.Id = Int32.Parse(dgvStrands.CurrentRow.Cells[0].FormattedValue.ToString());
                strand.Delete();

                //call load record to refresh list
                this.LoadRecords();

                //reset all objects
                this.Reset();

                pnlEdit.Visible = false;
                pnlNew.Visible  = true;
                btnAdd.Enabled  = true;
            }
        }