private void setDataSourceToGrid() { //here um setting the data source for this data grid dgvStudentDetails.DataSource = null; systemManager objsystemManager = new systemManager(); List <Student> lstStudent = new List <Student>(); lstStudent = objsystemManager.GetStudentBasicData(); StudentDetails objStudentDetails; List <StudentDetails> lstStudentDetails = new List <StudentDetails>(); foreach (var item in lstStudent) { objStudentDetails = new StudentDetails(); objStudentDetails.firstName = item.FullName; objStudentDetails.age = item.age; objStudentDetails.dateOfBirth = item.dateOfBirth; objStudentDetails.universityID = item.universityID; objStudentDetails.StudentID = item.StudentID; objStudentDetails.adress = item.adress; objStudentDetails.DepartmentName = item.ObjDepartment.DepartmentName; objStudentDetails.DepartmentID = item.ObjDepartment.DepartmentID; lstStudentDetails.Add(objStudentDetails); } dgvStudentDetails.DataSource = lstStudentDetails; }
//method which loads the studentID and name into the combobox. public void setCmbStudent() { systemManager objsystemManager = new systemManager(); cmbStudentID.DataSource = objsystemManager.GetStudentBasicData(); cmbStudentID.ValueMember = "StudentID"; cmbStudentID.DisplayMember = "universityID"; //because of this department combo's display inedex will shown as a blank index cmbStudentID.SelectedIndex = -1; }