在Form1
中,为什么myListBox
在name
课程中显示我的Student
属性
Form1
private static List<Student> studentListHome = new List<Student>();
...
public void BindData()
{
if (studentListHome != null)
{
studentListBox.DataSource = studentListHome;
studentListBox.DisplayMember = "name";
}
}
private void refreshButton_Click(object sender, EventArgs e)
{
BindData();
}
Student
private string name;
public string Name
{
get
{
return name;
}
}
...
public Student(string _name, int _id, string _bday)
{
name = _name;
id = _id;
bday = _bday;
}
答案 0 :(得分:0)
因为'name'是私人字符串。
尝试使用属性的“名称”。
studentListBox.DisplayMember = "Name";
答案 1 :(得分:0)
这解决了它
更改
studentListBox.DisplayMember = "Name";
要
foreach(Student s in studentListHome){
studentListBox.DisplayMember = "Name";
}