从结构数组中填充组合框

时间:2013-07-27 18:43:52

标签: c# arrays combobox

我有一个课程如下:

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=namevalueMember=pId

我已经尝试过但不起作用。

combobox1.DataSource = new BindingSource(centerVillage, null);
combobox1.DisplayMember = "name";
combobox1.ValueMember = "pId";

0 个答案:

没有答案