自定义类一个Category类如下,这个类要绑定到一个combox
 public class Category
    {
        private string _categoryid;
        private string _categoryname;        public string CategoryName
        {
            get { return _categoryname; }
            set { _categoryname = value; }
        }
        public string CategoryId
        {
            get { return _categoryid; }
            set { _categoryid = value; }
        }
        public override string ToString()
        {
            return CategoryName;
        }
我的问题是怎么把category表中的CategoryID和CategoryName字段添加到这个类的两个字段中
大侠们给个思路 代码最好 谢了 分不多

解决方案 »

  1.   

    Ilist<Category> list = new List<Category>();
    list.Add(new Category());combobox.dataSource = list;
    combobox.ValueMember = "CategoryID";
    combobox.DisplayMember = "CategoryName";
      

  2.   

    public string CategoryId
      {
      get ; 
      set; 
      }
    List<Category> lst= new List<Category>();combobox.dataSource = lst;
    combobox.ValueMember = "CategoryID";
    combobox.DisplayMember = "CategoryName";
      

  3.   

    先从库里读出来
    List<Category> lst= new List<Category>();// 先弄个实体类然后放泛型里 //从库里读LZ应该会吧combobox.dataSource = lst;
    combobox.ValueMember = "CategoryID";
    combobox.DisplayMember = "CategoryName";
      

  4.   

    额 还真不知道怎么从库里添加到List中
    还有 重写了TOstring方法以后还需要设置combox的valuemember吗?