数据库数据:
运行效果:
绑定自定义数据:
[代码+解释]
private void MainForm_Load(object sender, EventArgs e)
{
string sql = "select type from Type";
//下拉款绑定自定义数据
DataTable table = DBHelper.read(sql);
DataRow dr = table.NewRow();
dr[0] = "-----请选择-----";
table.Rows.InsertAt(dr, 0);
CBox_ZDY.DataSource = table;
CBox_ZDY.DisplayMember = "type";
}
绑定数据库数据:
[代码+解释]
private void MainForm_Load(object sender, EventArgs e)
{
string sql = "select type from Type";
//下拉框绑定数据库数据
CBox_SJK.DataSource = DBHelper.read(sql);
CBox_SJK.DisplayMember = "type";
}
总结[如何为ComboBox绑定数据]:
- 有自定义数据,先添加自定义数据
- 为ComboBox绑定DataSource数据源
- 再绑定ValueMember实际值,和DisplayMember 显示值
温馨提示:
喜欢灰碟分享的小伙伴不要忘记关注噢~这样子,想找我时就不会迷路啦*
联系方式:
Vx+:LHD7575