【发布时间】:2015-12-04 12:27:17
【问题描述】:
我的数据绑定设置与此相同 Visual Studio Winform designer: Set DataBindings on current control BindingSource
但我不知道如何改变假设我有 2 个模型的值:
class Receipt {
public int ProductId { get; set; }
public double Price { get; set; }
//etc...
}
class Product {
public int ProductId { get; set; }
public string ProductName { get; set; }
//etc...
}
My datagrid shows the Receipt model and when one is selected, my textboxes shows other details which are not displayed in the datagrid.
现在我的问题是我需要在我的文本框中显示 ProductName 而不是 ProductId。
我首先使用实体框架代码。 请帮忙...
TIA。
【问题讨论】:
-
您应该有某种方法可以使用所选收据中的 ProductId 获取产品实例。如果您使用的是 SQL,则应从中选择产品。
-
你使用实体框架吗?
-
@RezaAghaei - 是的,我使用的是代码优先
-
当你加载你的
Receipt时,也加载它的Product。然后您可以简单地使用它的Product.ToString()或将TextBox绑定到它的Product.ProductName -
如果您对答案有任何疑问,请告诉我:)
标签: c# winforms data-binding