添加到您的Person类返回预期
class Person
{
public int Person_ID {get;set;}
public string name {get;set;}
public string family {get;set;}
public int address {get;set;}
public string name_family { get {return this.ToString();}}
public override string ToString()
{
return string.Format("{0} {1}", this.name, this.family);
}
}
现在分配组合框的只读属性和ValueMember属性类Person的PERSON_ID的财产DisplayMember
字符串只读属性。
comboBox1.DataSource = PersonList;
comboBox1.DisplayMember = "name_family";
comboBox1.ValueMember = "id";
现在在ComboBox SelectedIndexChange
事件中,你可以检索从SelectedItemValue
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(comboBox1.SelectedValue != null)
{
int personID = Convert.ToInt32(comboBox1.SelectedValue);
.......
}
}
谢谢你的答案ID,但仍然没有解决一个问题?如果我通过单击这个工作来放置一个按钮:PersonList.RemoveAt(0);如果没有进一步的编程,我不想看到comboBox的第一项。可能吗? – user2373198 2013-05-11 19:50:16