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 DocRegHourrelated to a source of DataGrids elements. I want them to be grouped by GroupTypeID, as you can see what 2 classes have PaytypeOID.

I tried to make an unrelated collapsed column with Header = "Group"and set GroupTypeIDas text on each row. Then I wrote:

var pcv = new PagedCollectionView(dataGridDayView.ItemsSource);
pcv.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
dataGridDayView.ItemsSource = pcv;

However, this does not work. Any help?

To clarify. I have:

IEnumerable<DocRegHour> data;
IENumerable<EmpIDPayTypeSettings> userSettings;

var pcv = new PagedCollectionView(data);
dataGridDayView.ItemsSource = pcv;

I want to group by GroupTypeID !, which is in a different collection

+5
source share
2 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);

. , . , , :)

+1

, PropertyGroupDescriptor , Name , .

DocRegHour "", PagedCollectionView .

, "" PropertyGroupDescriptor.

+1

All Articles