这里发生的情况是,当我单击 myListBox 中的学生以打开他们的详细信息时,将显示一个显示其详细信息的窗口窗体,并且将显示一个显示 myListBox 中第一个教师详细信息的窗口窗体。
如果我单击 myListBox 中的教师,则会为他们打开一个窗口,这就是我想要的。对于学生,我怎样才能让它像这样工作?我是否有可能做类似的事情:
if(myListBox.SelectedIndex == Student)
{
//code to open details form here
}
这就是我为人们打开详细信息表单的方式。如果我没有使用 myListBox.SelectedIndex == index 的 if 语句。然后将打开每个人的详细信息表。
private void openInfoButton_Click(object sender, EventArgs e)
{
int index = 0;
foreach (Student student in studentsList)
{
if (myListBox.SelectedIndex == index)
{
PersonDetails studentDetails = new PersonDetails(student);
studentDetails.Show();
break;
}
index++;
}
foreach (Teacher teacher in teacherList)
{
if (myListBox.SelectedIndex == index)
{
PersonDetails teacherDetails = new PersonDetails(teacher);
teacherDetails.Show();
break;
}
index++;
}
}