我有一个课程如下:
class villages
{
public string name;
public int pId;
}
我以这样的形式使用它:
private villages[] centerVillage=new villages[]{
new villages{name= "village1",pId=0},
new villages{name= "village2",pId=1},
new villages{name= "village3",pId=2},
new villages{name= "village4",pId=3},
new villages{name= "village5",pId=4},
new villages{name= "village6",pId=5},
new villages{name= "village7",pId=6},
};
现在,我想从combobox1
填充villages[]
DisplayMember=name
和valueMember=pId
我已经尝试过但不起作用。
combobox1.DataSource = new BindingSource(centerVillage, null);
combobox1.DisplayMember = "name";
combobox1.ValueMember = "pId";