private void btnUpdate_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { FormRegistration2 rf2 = new FormRegistration2(); rf2.tbStudentNumber.ReadOnly = true; //employee number cannot be edited rf2.btnClear.Enabled = false; //clear button is disabled rf2.btnSave.Text = "Update"; //the save button is renamed to 'update' rf2.tbStudentNumber.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); rf2.tbFirstname.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString(); rf2.tbMiddlename.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString(); rf2.tbSurname.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString(); rf2.dtpDOB.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString(); rf2.comboBoxGender.Text = dataGridView1.SelectedRows[0].Cells[5].Value.ToString(); rf2.dtpRegDate.Text = dataGridView1.SelectedRows[0].Cells[6].Value.ToString(); rf2.comboBoxCourse.Text = dataGridView1.SelectedRows[0].Cells[7].Value.ToString(); rf2.tbCourseFee.Text = dataGridView1.SelectedRows[0].Cells[8].Value.ToString(); rf2.ShowDialog(); this.LoadData(); } else { MessageBox.Show("Please select a record for updation.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnInsert_Click(object sender, EventArgs e) { FormRegistration2 fr2 = new FormRegistration2(); fr2.ShowDialog(); //calling the dialog to register student details this.LoadData(); //showing data on the gridview that has been saved from the form }