Linq-to-sql 绑定到 FK 的组合框中未显示空值
我有一个绑定到 FK 实体(对象,而不是 ID 字段)的组合框。该组合框填充有 Linq-query-ToList()。 DisplayMember 已设置,ValueMember 为空。属性 SelectedItem 用于绑定。这一切都工作正常,除非 FK 为空/空,组合框中的第一项被选中,而如果我检查 Linq 对象,我可以看到 FK 为空。在这种情况下,我希望组合框的选定项也为空。我错过了什么吗?
I've a combobox that is binded to a FK entity (the object, not the ID-field). The combobox is filled with a Linq-query-ToList(). DisplayMember is set, ValueMember is empty. Property SelectedItem is used for binding. This all works fine, except if the FK is empty/null, the first item in the combobox is selected, while if I check out the Linq-object I can see that the FK is null. In this case I want the selecteditem of the combobox to be null as well. Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来这有效:
取自 http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/a530f011-54d9-44d1-a585-145ea28ff370/
“我已经测试了这个解决方案,但是如果您绑定到自定义对象并将对象的属性(绑定到组合框)设置为空值,这将无济于事。 注意:我正在绑定 SelectedItem。 我的解决方案
是派生组合框并强制 SelectedItem 正确运行”
It seems that this works:
Taken from http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/a530f011-54d9-44d1-a585-145ea28ff370/
"I've tested this solution but this will not help if you bind to custom object and set property of object (which is bound to combobox) to null value. Note: I'm binding SelectedItem property
my solution to is derive combobox and force SelectedItem to act correctly"