//Reading values in the data grid and assigning values to student object private List<StudentProperty> GetValuesFromDataGridView() { List<StudentProperty> objStudentPropertyList = new List<StudentProperty>(); for (int i = 0; i <= gvStudentDetails.Rows.Count - 1; i++) { StudentProperty objStudentProperty = new StudentProperty(); objStudentProperty.Active = Convert.ToBoolean(gvStudentDetails.Rows[i].Cells[4].Value.ToString()); objStudentProperty.DOB = Convert.ToDateTime(gvStudentDetails.Rows[i].Cells[2].Value.ToString()); objStudentProperty.GradePointAvg = (decimal)gvStudentDetails.Rows[i].Cells[3].Value; objStudentProperty.Name = gvStudentDetails.Rows[i].Cells[1].Value.ToString(); objStudentProperty.StudentID = gvStudentDetails.Rows[i].Cells[0].Value.ToString(); //Adding sdtudent objects to list objStudentPropertyList.Add(objStudentProperty); } return objStudentPropertyList; }
//Getting control values and assigning values to Student object private StudentProperty GetValuesFromControls() { StudentProperty objStudentProp = new StudentProperty(); objStudentProp.DOB = dtpDOB.Value; decimal decGPA; //Checking whether the GPA value is a decimal value bool blnGPA = decimal.TryParse(txtGPA.Text, out decGPA); if (blnGPA) { objStudentProp.GradePointAvg = decimal.Parse(txtGPA.Text); } else { MessageBox.Show("Invalid GPA"); txtGPA.Focus(); txtGPA.Text = "0.0"; } objStudentProp.Name = txtName.Text; objStudentProp.StudentID = lblStudentID.Text; objStudentProp.Active = chkActive.Checked; return objStudentProp; }