I have an Employee class:
class Employee
{
public string Name { get; set; }
public string SurName { get; set; }
public int Rest{ get; set; }
public int Worked { get; set; }
public List<int> PerShift= new List<int>();
}
In my database, I save how many times an employee worked in 1st shift how many in 2nd etc. Then in my datagrid, I want to see how many times each employee worked in total, how many days he rested and how many days he worked in each shift. The thing is that shift number is set by user, so I have to programmatically add those columns
<DataGrid Name="EmployeesStatsDatagrid"
Grid.Row="1"
IsReadOnly="True"
CanUserAddRows="False" CanUserReorderColumns="False"
Grid.ColumnSpan="4"
Grid.Column="0"
IsSynchronizedWithCurrentItem="True"
CanUserDeleteRows="False"
CanUserResizeRows="False"
AutoGenerateColumns="False"
VerticalAlignment="Stretch">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name}" />
<DataGridTextColumn Header="Surname" Binding="{Binding SureName}" />
<DataGridTextColumn Header="Rest" Binding="{Binding Rest}" />
<DataGridTextColumn Header="Δούλεψε" Binding="{Binding Worked}" />
</DataGrid.Columns>
</DataGrid>
Then I add the extra columns
for (int i = 0; i < Collections.ShiftsCollection.Count; i++)
{
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = Collections.ShiftsCollection[i].ShiftName.ToUpper();
//textColumn.Binding = new Binding(Collections.ShiftsCollection[i].ShiftName);
EmployeesStatsDatagrid.Columns.Add(textColumn);
}
The columns are properly set, I create a list of Employees and binding works for name, surname, worked and rest, but how can I bind the extra columns to the List<int> PerShift? Any ideas? Or should I implement it differently?
For example in this case I have two shifts, morning and afternoon, first employees PerShift list is {4,0} and second is {0,1} is there a way to have those values in the column binded? I hardcoded them in this case but if I sort columns values are lost.

PerShiftlist. Also try to explain how you want to visualize these list inside your data grid.AfternoonandMorninginstead of using a list?