简体   繁体   English

WPF Datagrid动态绑定

[英]WPF Datagrid Dynamic Binding

This is a little complicated I think, I'll do my best to explain. 我认为这有点复杂,我会尽力解释。

I have the following tables; 我有下表。

Timesheets 时间表
idTimesheet idTimesheet
id_User id_User
EndDate 结束日期
Submitted 提交
Approved 批准

LineItems 了LineItem
idLineItem idLineItem
id_Timesheet id_Timesheet
Description 描述

Days
idDay idDay
id_LineItem id_LineItem
Date 日期
Hours 小时

So, as you can see, this is a Timesheeting system. 如您所见,这是一个时间表系统。 I've gotten myself to the point where I can display each line item individually, the problem is figuring out how to display the hours for each day in the relevant column. 我已经可以单独显示每个订单项了,问题是正在弄清楚如何在相关列中显示每天的小时数。

I'm using Timesheets.EndDate to dynamically generate the Day columns in the GridView so that they can have the date in each column too, but I'm at a loss as to how to bind the days/hours to the relevant column. 我正在使用Timesheets.EndDate在GridView中动态生成Day列,以便它们也可以在每个列中都有日期,但是我对如何将天/小时绑定到相关列感到困惑。 They are DataGridTextColumns as the end goal is to allow the user to enter thier own hours into the system. 它们是DataGridTextColumns,因为最终目标是允许用户在系统中输入自己的小时数。 I'm using EntityFramework, so the Days can be aquired using LineItem.Ref_Days which provides an ICollection<Days> although, that can easily to be converted to a List or other useful object with the help of LINQ. 我正在使用EntityFramework,因此可以使用LineItem.Ref_Days来获取ICollection<Days>尽管LineItem.Ref_Days提供了ICollection<Days>但可以借助LINQ轻松将其转换为List或其他有用的对象。

Happy to provide more information if necessary. 如有必要,乐意提供更多信息。

how to display the hours for each day in the relevant column. 如何在相关列中显示每天的小时数。

Don't try to use a straight entity and bind to properties which don't expose what is needed. 不要尝试使用直接实体并绑定到不会暴露所需内容的属性。 Either create a Data Transfer Object (DTO) object with the business logic (and all models which make up the logic) needed expressed as properties which draw from the original properties, or extend the entity from EF via a partial class definition. 创建具有所需业务逻辑(以及构成逻辑的所有模型)的数据传输对象(DTO)对象,这些业务逻辑表示为从原始属性中提取的属性,或者通过部分类定义从EF扩展实体。 Put in the smarts to update the actual properties in the setters of the new properties created. 放入智能工具以在创建的新属性的设置器中更新实际属性。

Either way you simply bind the columns to the new properties either on the actual extended entity or the DTO. 无论哪种方式,您都可以简单地将列绑定到实际扩展实体或DTO上的新属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM