美文网首页
WinForm Combox使用

WinForm Combox使用

作者: QT2019NB | 来源:发表于2021-02-03 15:48 被阅读0次

1.查询出数据源

List<Student> students = new List<Student>()
{
    new Student{ Id = 1, Name = "张三" },
    new Student{ Id = 2, Name = "李四" },
    new Student{ Id = 3, Name = "王五" }
};

2.数据绑定

// 下拉框的展示文本
combox1.DisplayMember = "Name";
// 下拉框的值
combox1.ValueMember = "Id";
combox1.DataSource = students;

3.给下拉框设置默认选中项

// 给下拉框设置默认选中项的值
combox1.SelectedValue = 2;

4.如何获取选中项的值

Student stu = combox1.SelectedItem as Student;

相关文章

网友评论

      本文标题:WinForm Combox使用

      本文链接:https://www.haomeiwen.com/subject/mlqmtltx.html