コード例 #1
0
        private void dgvOtherFee_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                id = Convert.ToInt32(dgvOtherFee.Rows[e.RowIndex].Cells[2].Value.ToString());//for editing criteria

                //pass value to edit mode
                txtOtherFeeName.Text = dgvOtherFee.Rows[e.RowIndex].Cells[3].Value.ToString(); //Name
                txtAmount.Text       = dgvOtherFee.Rows[e.RowIndex].Cells[4].Value.ToString(); //Name
                cmbStrand.Text       = dgvOtherFee.Rows[e.RowIndex].Cells[5].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)
                {
                    otherFee.Id = Convert.ToInt32(dgvOtherFee.Rows[e.RowIndex].Cells[2].Value.ToString());//for editing criteria
                    otherFee.Delete();

                    otherFee.LoadDataTable(dgvOtherFee);
                }
                else
                {
                    return;
                }
            }
        }
コード例 #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
                otherFee.Id = Int32.Parse(dgvOtherFee.CurrentRow.Cells[0].FormattedValue.ToString());
                otherFee.Delete();

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

                //reset all objects
                this.Reset();

                pnlEditFee.Visible = false;
                pnlNewFee.Visible  = true;
                btnAdd.Enabled     = true;
            }
        }