private void button2_Click(object sender, EventArgs e)
{
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.Items.Add("云南");
comboBox1.Items.Add("上海");
Class1 c1 = new Class1();
c1.Id = "01";
c1.Name = "云南01";
Class1 c2 = new Class1();
c2.Id = "02";
c2.Name = "上海02";
List<Class1> clist= new List<Class1>();
clist.Add(c1);
clist.Add(c2);
comboBox1.DataSource = clist;
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "Id";
}
private void button3_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedValue== null)
{
MessageBox.Show("combox里面没有值");
}
else
{
MessageBox.Show(comboBox1.Text + "/" + comboBox1.SelectedValue.ToString());
}
}