带Key,Value的ComboboxEdit

CmbInfo:

struct CmbInfo
    {
        public int _key;
        public string _text;
        public CmbInfo(int key, string text) 
     {
       _key
= key; _text = text;
     }
     public override string ToString()
     {
       
return _text;
     }
  }
comboBoxEdit赋值:
       ComboBoxItemCollection col1 = comboBoxEdit1.Properties.Items;
            col1.BeginUpdate();
            col1.Add(new CmbInfo(1,"111"));
            col1.Add(new CmbInfo(2, "222"));

取值:

       CmbInfo p=new CmbInfo ();
            p = (CmbInfo)(comboBoxEdit1.SelectedItem);
            string text = p._text;
            int value = p._key;
            MessageBox.Show(text + "  " + value.ToString());
posted @ 2012-05-06 22:17  wowait2  阅读(310)  评论(0)    收藏  举报