c#中combox赋值

class item
  {
  public string Txt { get; set; }
  public string value { get; set; }

  public override string ToString()
  {
  return Txt;
  }
  }
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }

    

  private void Form1_Load(object sender, EventArgs e)
  {

  item school = new item() {Txt="学校",value="0" };
  item student = new item() { Txt = "学生", value = "1" };
  item score = new item() { Txt = "成绩", value = "2" };
  comboBox1.Items.Add(school);
    
  comboBox1.Items.Add(student);
  comboBox1.Items.Add(score);
  }



  private void button2_Click(object sender, EventArgs e)
  {
  MessageBox.Show((this.comboBox1.SelectedItem as item).value);
  }
  }

你可能感兴趣的:(c#中combox赋值)