this.combox1.selectedindex -----獲取combox的索引,索引從0開始。
this.combox1.SelectedItem -------獲取combox的內容。
this.combox1.Text ------------------獲取combox的內容,跟this.combox1.selectitem一樣的作用。
this.combox1.item.clear() --------清除combox1里面的內容。
this.combox1.item.add() ----------為combox1添加內容。
this.combox1.item.AddRange(object [] items) ---為combox1添加多個內容。
this.combox1.Items.Count -------獲取combox1內容的個數。
//加載界面時為combox1賦值,同時顯示時默認第一個
private void Form1_Load(object sender, EventArgs e)
{
this.combox1.Items.AddRange(new object[] { "Jack", "Rose", "Elepht", "Tim", "Fock" });
this.combox1.SelectedIndex = 0;
}
//combox1下拉觸發事件
private void combox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.label1.Text = this.combox1.SelectedItem.ToString();
}
//combox1下拉觸發事件
private void combox1_SelectedValueChanged(object sender, EventArgs e)
{
this.label2.Text = this.combox1.SelectedIndex.ToString();
}