首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

ComboBox设立Key,Value

2012-12-26 
ComboBox设置Key,Valueclass Option{public string Key { get set }public string Value { get set }p

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); 

热点排行