读书人

ComboBox设立Key,Value

发布时间: 2012-12-26 14:39:29 作者: rapoo

ComboBox设置Key,Value

 class Option    {      public string Key { get; set; }         public string Value { get; set; }       public Option(string pKey, string pValue)         {          this.Key = pKey;          this.Value = pValue;         }        }


设置
   Option option = new Option("1", "金额");      this.combobox1.Items.Add(option );      // 在此可以增加N个      this.combobox1.Items.Add(option );      // 对应 ListItem 的  Value  显示值   this.combobox1.DisplayMember = "Value";   // 对应 ListItem 的  Key    隐藏值   this.combobox1.ValueMember = "Key";


读取
   Option option = (Option )comboBox1.SelectedItem;      MessageBox.Show(option .Key + option .Value); 

读书人网 >编程

热点推荐