2010年4月15日 星期四

C# WinForm ComboBox 自訂text 及 value

private void Form1_Load(object sender, System.EventArgs e)
  {
   ArrayList col= new ArrayList();   
   col.Add( new DictionaryEntry("Jack",1));
   col.Add(new DictionaryEntry("Joe",2));
   col.Add( new DictionaryEntry("Jules",3));  
       comboBox1.DisplayMember="Key";
   comboBox1.ValueMember ="Value";
   comboBox1.DataSource=col;   
  }
  private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
  {
    MessageBox.Show("You chose value: " +comboBox1.SelectedValue  );
  }

沒有留言:

張貼留言