// 添加数据方法            ArrayList Dic = new ArrayList();
            DictionaryEntry entry = new DictionaryEntry();
            int m_taskListCount = this.m_taskList.Count;
           
            for (int i = 0; i < m_taskListCount; i++)
            {
                entry.Key = m_taskList.Item(i).Attribute(”id”);
                entry.Value = m_taskList.Item(i).Value;
                Dic.Add(entry);
            }
            CbTaskList.DataSource = Dic;
            CbTaskList.DisplayMember = “value”;
            CbTaskList.ValueMember = “key”;// 使用方法            foreach (object i in CbTaskList.Items)
            {
                if (((DictionaryEntry)i).Key.ToString() == taskId)
                {
                    CbTaskList.SelectedItem = i;
                    return;
                }
            }Tags: Combobox遍历
Posted in .net | 1 Comment »WinForm给ComboBox增加Value(转)
January 7th, 2008 
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”;