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

}

猜你喜欢

转载自www.cnblogs.com/dongjingwu/p/9695742.html