public partial class Aboutcbo : Form
{
public Aboutcbo()
{
InitializeComponent();
}
private void Aboutcbo_Load(object sender, EventArgs e)
{
List<StudentInfo> students = new List<StudentInfo>()
{
new StudentInfo() {StuID="001",StuName="张三",StuSex="男",StuAge=15,StuTel="1212121",StuDorm="302"},
new StudentInfo() {StuID="002",StuName="王五",StuSex="男",StuAge=15,StuTel="1212121",StuDorm="302"},
new StudentInfo() {StuID="003",StuName="李四",StuSex="男",StuAge=15,StuTel="1212121",StuDorm="302"},
new StudentInfo() {StuID="004",StuName="刘红",StuSex="女人",StuAge=15,StuTel="1212121",StuDorm="302"}
};
this.comboBox1.DisplayMember = "StuName";//设置该属性以显示下拉框列表
this.comboBox1.ValueMember = "StuID";//该属性为选择的Item实际值
this.comboBox1.DataSource = students;
this.comboBox1.SelectedIndex = 0;
}
/// <summary>
/// 下拉框属性更改事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(this.comboBox1.SelectedValue.ToString());
//001 002 003
}
}
WinForm_ComboBox显示值、实际值
猜你喜欢
转载自blog.csdn.net/MrLsss/article/details/105646857
今日推荐
周排行