如何填充DataGridViewComboBoxColumn

时间:2013-02-10 05:54:18

标签: c# winforms linq datagridview

我的DataGridViewComboBoxColumn中有datagridview,我希望在运行时使用linq填充:

我试试这个

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";

但是这没用。那么如何将数据绑定到ComboBox

中的DataGridView

1 个答案:

答案 0 :(得分:0)

试试这个:

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