public StudentWindow() { InitializeComponent(); int groupId = otherData.GetStudentsGroup(student.Name, student.Surname); userLabel.Text += student.Name + " " + student.Surname; List <Subject_Group> allSubjectsAndGroups = otherData.GetAllSubject_Group(); List <Subject> allAssignedsubjectsList = otherData.GetAllAssignedSubjects(); List <Subject_Group> studentsSubjectsAndGroupIds = new List <Subject_Group>(); List <Subject> studentSubjects = new List <Subject>(); foreach (Subject_Group subject_Group in allSubjectsAndGroups) { if (subject_Group.Group_id == groupId) { studentsSubjectsAndGroupIds.Add(subject_Group); // Pridedami į listą visi studento subjectsid } } foreach (Subject subject in allAssignedsubjectsList) { foreach (Subject_Group subject_Group in studentsSubjectsAndGroupIds) { if (subject_Group.Subject_id == subject.Id) { studentSubjects.Add(subject); // Pridedami į listą visi studento subjects } } } int width = SubjectsLayoutPanel.Width - 7; foreach (Subject subject in studentSubjects) { Button subjectButton = new Button(); subjectButton.Text = subject.Title; subjectButton.Width = width; subjectButton.UseVisualStyleBackColor = true; subjectButton.Tag = subject; subjectButton.Click += SubjectButton_Click; SubjectsLayoutPanel.Controls.Add(subjectButton); } }