我的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
答案 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