添加到您的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