Code Bye

List集合绑定到ComboBox

 public class Item
 {
     public string key;
     public string value;
  }
此时不能直接将List<Item>绑定到ComboBox 
 cob.DataSource = items.itemCollection;
 cob.DisplayMember = "Value";
 cob.ValueMember = "Key";
 必须将Item类修改为
public class Item
 {
     private string key;
 
     public string Key
     {
         get { return key; }
         set { key = value; }
     }
     private string value;
 
     public string Value
     {
         get { return this.value; }
         set { this.value = value; }
     }
 }

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明List集合绑定到ComboBox