码迷,mamicode.com
首页 > Windows程序 > 详细

c#中combox赋值

时间:2015-11-04 10:11:19      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:

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赋值

标签:

原文地址:http://my.oschina.net/sexgirl/blog/525581

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!