组合框中的arraylist然后列表框

时间:2016-01-18 20:35:44

标签: c# class arraylist

我有一个名为arraylist的数组列表,数据从文本文件读入 - 然后读入类(称为教师和学生),然后按如下方式存储到数组列表中:

[0]TEACHER
[1]STUDENT
[2]STUDENT
[3]TEACHER
[4]STUDENT

每位教师都有自己的详细信息。

我如何与阵列列表中的所有教师一起填充组合框 - 然后根据组合框中选择的教师....相应的学生选择的教师填写另一个列表框..

我正在考虑用老师填充组合框:

    //method to populate combobox (cboWhichTeacher)
    {
        foreach (Teacher t in arraylist)
        {
            string selectedTeacher;
            selectedTeacher = t.getTeacherName();
            cboWhichTeacher.Items.Add(selectedTeacher);
        }
        cboWhichTeacher.SelectedIndex = 0;

并且为了得到相应的学生我不太确定:         }

    public static int studentSelected = -1;

    private void lst_SelectedIndexChanged(object sender, EventArgs e)
    {
        frmTeacher.studentSelected = lstStudent.SelectedIndex;
    }

    private void cboWhichSwitch_SelectedIndexChanged(object sender, EventArgs e)
    {
        string output;
        foreach (Teacher t in arraylist)
        {
            foreach (Student s in s.getAllTeacherStudents())
            {
                output = ("Teacher " + s.getstudentname() + "no students");
                lstStudent.Items.Add(output);
            }
        }
    }

0 个答案:

没有答案