List集合绑定到ComboBox

.Net技术 码拜 11年前 (2013-04-20) 1273次浏览 0个评论
 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
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!