1. 程式人生 > >WinForm中讓ComboBox Add 鍵值對

WinForm中讓ComboBox Add 鍵值對

第一次做WinForm應用程式,居然發現 ComboBox 不能像DropDownList使用鍵值對,網上資料找得也幸苦,終於找到一種比較實用的方法:   ArrayList mylist =new ArrayList();
  mylist.Add (
new DictionaryEntry ("1",""));
  mylist.Add (
new DictionaryEntry ("2","不好"));
  mylist.Add (
new DictionaryEntry ("3","一般"));
  mylist.Add (
new DictionaryEntry ("4",""));
  mylist.Add (
new DictionaryEntry ("5","太好了"));
  comboBox1.DataSource 
=mylist; 
  comboBox1.DisplayMember 
="Key";
  comboBox1.ValueMember 
="Value"