displaymember是指在绑定控件中显示出来的名称,valuemember是显示出来的名称所对应的值。在给这两个属性赋值的时候,是指定数据表中的字段名称。
textBox1.Location = new Point(24, 160) ;
textBox1.Name = "textBox1" ;
textBox1.Size = new Size(240, 24) ;
this.Controls.AddRange(new Control[] {ListBox1, textBox1}) ;
// Populates the list box using DataSource.
// DisplayMember is used to display just the long name of each state.
ArrayList USStates = new ArrayList() ;
USStates.Add(new USState("Alabama", "AL"));
USStates.Add(new USState("Washington", "WA")) ;
USStates.Add(new USState("West Virginia", "WV"));
USStates.Add(new USState("Wisconsin", "WI")) ;
USStates.Add(new USState("Wyoming", "WY"));
ListBox1.SelectedValueChanged += new EventHandler(ListBox1_SelectedValueChanged);
ListBox1.DataSource = USStates ;
ListBox1.DisplayMember = "LongName" ;
ListBox1.ValueMember = "ShortName" ;