Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PagedViewCollection group by column, not property

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

like image 737
CasperT Avatar asked Nov 05 '22 22:11

CasperT


1 Answers

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 :)

like image 177
LueTm Avatar answered Nov 12 '22 16:11

LueTm