list泛型绑定cbo出现无法绑定到新的显示成员

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace FlashDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;


        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }


        #region Windows 窗体设计器生成的代码


        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.cbDepart = new System.Windows.Forms.ComboBox();
            this.SuspendLayout();
            // 
            // comboBox1
            // 
            this.cbDepart.FormattingEnabled = true;
            this.cbDepart.Location = new System.Drawing.Point(100, 55);
            this.cbDepart.Name = "comboBox1";
            this.cbDepart.Size = new System.Drawing.Size(121, 20);
            this.cbDepart.TabIndex = 0;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.cbDepart);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);


        }


        #endregion


        private System.Windows.Forms.ComboBox cbDepart;
        private void Form1_Load(object sender, EventArgs e)
        {
            BindComBox();
     this.cbDepart.SelectedValue="3";




        }
          private void BindComBox()
         {
             List <Depart>list = new List<Depart>();
             Depart d1 = new Depart( "1", "销售部" );
             Depart d2 = new Depart ( "2", "技术部" );
             Depart d3 = new Depart ("3", "生产部" );
             list.Add(d1);
             list.Add(d2);
             list.Add(d3);  
              cbDepart.DataSource = list;
              cbDepart.DisplayMember = "DepartName";


             cbDepart.ValueMember = "ID";
           
        
         }  
    }
    public class Depart
    {
        protected string _ID;
        protected string _DepartName;
        public
            Depart(string ID, string DepartName)
        {
            this._ID = ID;
            this._DepartName = DepartName;
        }
        public string ID
        {
            get
            {
                return this._ID;


            }
            set
            {
                _ID = value;
            }
        }
        public string DepartName
        {
            get
            {
                return _DepartName;
            }
            set
            {
                _DepartName = value;
            }
        }
    }
}

你可能感兴趣的:(list泛型绑定cbo出现无法绑定到新的显示成员)