private void FrmAddStudent_Load(object sender, EventArgs e) { StudentClassServer studentClassServer = new StudentClassServer(); List<StudentClass> students = studentClassServer.GetStudentClasses(); //获取下拉框的数据 //向集合第一个位置插入一条数据 students.Insert(0,new StudentClass() { ClassId = 0, ClassName="请选择班级" }); this.comboBox1.DataSource = students; // 将数据赋值给下拉框 this.comboBox1.DisplayMember = "ClassName"; //设置下拉框的 label值 this.comboBox1.ValueMember = "ClassId"; //设置下拉框的value值 this.comboBox1.SelectedIndex = 1; //设置默认选择 }
标签:ClassId,StudentClassServer,students,comboBox,基础,studentClassServer,comboBox1,下拉框 From: https://www.cnblogs.com/tlfe/p/18243318
StudentClassServer 类此次省略了,如果想查看的话可以点击 https://www.cnblogs.com/tlfe/p/18243303 查看