使用comboBox1控件进行数据加载现实
比如我要现实一个表
表名table1
列表1名
id
列表2名
name
使用select * from table1 查询出name用
comboBox1.Items.Add["name"]
我又想获取到当前combobox选项中的name对应的id的值如何获取呢?
比如我要现实一个表
表名table1
列表1名
id
列表2名
name
使用select * from table1 查询出name用
comboBox1.Items.Add["name"]
我又想获取到当前combobox选项中的name对应的id的值如何获取呢?
//绑定
private DataTable comboBoxSrc
{
set
{
comboBox1.DataSource = value;
comboBox1.ValueMember = "id";
comboBox1.DisplayMember = "name";
}
}//取值
string strId = comboBox1.SelectedValue.ToString();