I have these 2 classes:
class EmpIDPayTypeSettings
{
public Guid OID { get; set; }
public Guid PayTypeOID { get; set; }
public int GroupTypeID { get; set; }
public Guid EmpOID { get; set; }
public int OrderBy { get; set; }
}
class DocRegHour
{
public Guid OID { get; set; }
public Guid DocumentOID { get; set; }
public Guid medarbejderOID { get; set; }
public Guid PaytypeOID { get; set; }
public string PayTypeInfo { get; set; }
public double Hours { get; set; }
public string Comment { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime LastChangedDate { get; set; }
}
I have a collection of DocRegHour
bound to a DataGrids itemsource.
I want them grouped by GroupTypeID
, as you can see the 2 classes have PaytypeOID
in common.
I tried making a non-bound collapsed column with the Header = "Group"
and set the GroupTypeID
as text in each row.
Then I wrote:
var pcv = new PagedCollectionView(dataGridDayView.ItemsSource);
pcv.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
dataGridDayView.ItemsSource = pcv;
It doesn't work though. Any help?
To clarify. I have:
IEnumerable<DocRegHour> data;
IENumerable<EmpIDPayTypeSettings> userSettings;
var pcv = new PagedCollectionView(data);
dataGridDayView.ItemsSource = pcv;
Which I want to group by GroupTypeID!, which is in a different collection
If you do:
// LINQ the stuff you need and then group by the name you give it
myData.Where(...).Select(emp => new { Group = emp.GroupTypeID });
GroupDescriptor descriptor = new GroupDescriptor("Group");
pcv.GroupDescriptors.Add(descriptor);
It should work. I'm not entirely sure though I understood your data-model. However I found anonymous types to be pretty handy when it comes to similar situations :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With