combox簡單用法


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();        

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM