c#中combox赋值

原创
2015/11/04 08:49
阅读数 1.2K
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);
  }
  }
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部