【问题标题】:How to populate the DataGridViewComboBoxColumn如何填充 DataGridViewComboBoxColumn
【发布时间】:2023-03-12 13:45:01
【问题描述】:

我的datagridview 中有DataGridViewComboBoxColumn,我想在运行时使用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";

但这没有用。那么如何在我的DataGridView 中将数据绑定到ComboBox

【问题讨论】:

  • 我虽然你正在尝试添加一个 DataGridViewComboBoxColumn :)

标签: c# winforms linq datagridview


【解决方案1】:

试试这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-26
    • 2016-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多