前言:完成如下图
一。下拉列表框
public Form2()
{
InitializeComponent();//由系统生成的对于窗体界面的定义方法,初始化窗体组件的
}
public int index = -1;//设置
public int index1 = -1;
public int index2 = -1;
private void btnProp_Click(object sender, EventArgs e)
{
//comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;//文本部分不可编辑
comboBox1.DropDownStyle = ComboBoxStyle.DropDown;
string[] items = {
"1", "2", "3", "4" };
comboBox1.Items.AddRange(items);
comboBox1.SelectedIndex = 2; //设置
/* comboBox1.SelectedIndex = comboBox1.Items.Count - 1;//为什么要-1?以为0页计数*/
}
private void btnAdd1_Click(object sender, EventArgs e)
{
//判断输入内容是否重复
//comboBox1.Text = "添加的内容";
if ( string.IsNullOrEmpty(comboBox1.Text))
{
MessageBox.Show("没有输入内容","提示",MessageBoxButtons.OK);
return;
}
if (comboBox1.Items.Contains(comboBox1.Text))
{
MessageBox.Show("该项已存在,重新输入");
return;
}
comboBox1.Items.Add(comboBox1.Text);
comboBox1.SelectedItem = comboBox1.Text;
}
private void btnSearch1_Click(object sender, EventArgs e)
{
if (string.