C#中ComboBox能否设定多个ValueMenber?

来源:百度知道 编辑:UC知道 时间:2024/05/31 07:20:13
举个例子:
表student,有字段id,name,tel
有个combobox绑定了这个表,
其中DisplayMember设置为id,
现要取出对应的name和tel, 用ValueMember只能取一个,该怎么做呀?

一般是这样绑定和取值:
comboBox1.DataSource = student; //绑定student表为数据源
comboBox1.DisplayMember = "name";
comboBox1.ValueMember = "id";
string name = comboBox1.SelectedText;//取DisplayMember值
string id = comboBox1.SelectedValue.ToString();//取ValueMember值
DataTable table1 = this.comboBox1.DataSource as DataTable;
int rowIndex = this.comboBox1.SelectedIndex;
string str1 = table1.Rows[rowIndex]["tel"].ToString();//取绑定表中的其它值

一般是这样绑定和取值:
comboBox1.DataSource = student; //绑定student表为数据源
comboBox1.DisplayMember = "name";
comboBox1.ValueMember = "id";
string name = comboBox1.SelectedText;//取DisplayMember值
string id = comboBox1.SelectedValue.ToString();//取ValueMember值
DataTable table1 = this.comboBox1.DataSource as DataTable;
int rowIndex = this.comboBox1.SelectedIndex;
string str1 = table1.Rows[rowIndex]["tel"].ToString();//取绑定表中的其它值

不应该把D