繁体   English   中英

组合框填充了valueMember而不是DataGridView中的DisplayMember吗?

[英]Combo box is filling with valueMember not with the DisplayMember from DataGridView?

我正在填充组合框

cbDepartment.DataSource = SQLObject.Departments;
            cbDepartment.DisplayMember = "Name";
            cbDepartment.ValueMember = "Id";

和数据GridView这样

EmployeeGrd.DataSource = SQLObject.sp_ViewEmployee();

组合框填充了另一个表,该表是我的查找表“部门”,它仅包含“名称”和“ Id”,而DataGridView填充了存储过程,而该存储过程来自另一个表,该表仅包含部门表的“ Id”我正在从数据网格视图填充组合框,正在填充组合框中的“ Id”,我需要填充“名称”而不是“ Id”。

我正在这样填充组合框。

 comboBox1.SelectedText = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();

DataGridView单元具有属性FormattedValue ,这是您在此处需要使用的属性。

comboBox1.SelectedText = dataGridView1.SelectedRows[0].Cells[1].FormattedValue.ToString(); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM