[英]How to populate the DataGridViewComboBoxColumn
I have DataGridViewComboBoxColumn
in my datagridview
and I want to populate using linq
in run-time: 我的
datagridview
有DataGridViewComboBoxColumn
,我想在运行时使用linq
进行填充:
I try this 我尝试这个
var line = from li in dbdata.Production_lines select li;
grdEmp.Rows.Add();
(grdEmp.Rows[count].Cells["Line"] as DataGridViewComboBoxCell).DataSource = line;
(grdEmp.Rows[count].Cells["Line"] as DataGridViewComboBoxCell).ValueMember = "L_id";
(grdEmp.Rows[count].Cells["Line"] as DataGridViewComboBoxCell).DisplayMember = "L_id";
But this didn't work. 但这没有用。 so how do I bind the data to
ComboBox
in my DataGridView
所以如何将数据绑定到
DataGridView
ComboBox
Try this : 尝试这个 :
DataGridViewComboBoxColumn combo = (DataGridViewComboBoxColumn)grdEmp.Columns["Line"];
combo.DataSource = line;
combo.ValueMember = "L_id";
combo.DisplayMember = "L_id"; // I also suspect this should be a text column
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.