PagedViewCollection 按列而不是属性分组
我有这两个类:
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; }
}
我有一个绑定到 DataGrids 项源的 DocRegHour 集合。 我希望它们按 GroupTypeID
分组,因为您可以看到这两个类具有共同的 PaytypeOID
。
我尝试使用 Header = "Group"
创建一个非绑定折叠列,并将 GroupTypeID
设置为每行中的文本。 然后我写道:
var pcv = new PagedCollectionView(dataGridDayView.ItemsSource);
pcv.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
dataGridDayView.ItemsSource = pcv;
但这不起作用。有什么帮助吗?
澄清一下。我有:
IEnumerable<DocRegHour> data;
IENumerable<EmpIDPayTypeSettings> userSettings;
var pcv = new PagedCollectionView(data);
dataGridDayView.ItemsSource = pcv;
我想按 GroupTypeID 进行分组!,它位于不同的集合中
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你这样做:
它应该有效。尽管我理解你的数据模型,但我并不完全确定。然而,我发现在类似的情况下匿名类型非常方便:)
If you do:
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 :)
您的问题是 PropertyGroupDescriptor 期望用于对项目进行分组的 propertyName,而不是用于分组的列的标题。
您的类 DocRegHour 没有名为“Group”的属性,因此 PagedCollectionView 无法按此属性对项目进行分组。
要解决此问题,请将属性“Group”添加到您的类中或为 PropertyGroupDescriptor 指定另一个属性。
Your problem is that the PropertyGroupDescriptor expects the propertyName to group items by and not the header of the column to group by.
Your class DocRegHour does not have a property named "Group", so the PagedCollectionView cannot group items by this property.
To solve this, add a property "Group" to your class or specify another property for the PropertyGroupDescriptor.