【问题标题】:ComboBox ValueMember Error组合框值成员错误
【发布时间】:2014-02-05 20:21:54
【问题描述】:

我在我的 WinForm 应用程序中收到此错误:
不支持直接将数据绑定到存储查询(DbSet、DbQuery、DbSqlQuery)。而是使用数据填充 DbSet,例如通过在 DbSet 上调用 Load,然后绑定到本地数据。对于 WPF 绑定到 DbSet.Local。对于 WinForms 绑定到 DbSet.Local.ToBindingList()。

这是我的代码:

private DataBaseEntities entity = new DataBaseEntities();
categoryComboBox.DataSource = entity.TableName;
categoryComboBox.DisplayMember = "Description";
//ProductType is the Primary Key of the table and is Identity as well
//And when the compiler arrives here, the error is thrown
categoryComboBox.ValueMember = "ProductType"; 



有人可以帮我解决我的错误吗?

【问题讨论】:

    标签: c# winforms visual-studio-2012 error-handling


    【解决方案1】:

    您不能像这样直接将表格分配给网格。尝试将其转换为这样的列表

    categoryComboBox.DataSource = entity.TableName.ToList();
    

    这应该可行。

    【讨论】:

    • 谢谢哥们。它正在工作。我读过一篇关于这个错误的文章,但还有另一种情况。再次感谢@ElectricRouge。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 2014-05-14
    • 2021-11-06
    • 1970-01-01
    相关资源
    最近更新 更多