小孔子的快乐生活

WinForm给ComboBox增加Value(转)

做一个图书管理系统,用到了combobox,
天呀,竟然不能像DropDownList那样直接使用键值对的方式
百度了半天,终于找到方法,发出来大家共享
用DataTable可以!但是总不能象男,女这样两项也用一个DataTable吧, 这也太麻烦了啊!
用Hashtable,SortedList直接添加键值对都报错了!
经过我多方的考究,最后终于搞定了,就用ArrayList就可以了!
    代码可以这样写!
  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 ="Value";
  comboBox1.ValueMember ="Key";

posted on 2007-09-27 22:18  小孔子  阅读(1496)  评论(0编辑  收藏  举报

导航