Trent
Trent

Reputation: 1593

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
id_User
EndDate
Submitted
Approved

LineItems
idLineItem
id_Timesheet
Description

Days
idDay
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. They are DataGridTextColumns as the end goal is to allow the user to enter thier own hours into the system. 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.

Happy to provide more information if necessary.

Upvotes: 0

Views: 202

Answers (1)

ΩmegaMan
ΩmegaMan

Reputation: 31606

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. 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.

Upvotes: 1

Related Questions