如何在DataGrid中显示分组数据? -摘要行 [英] How to show the grouping data in a DataGrid? - Summary Row

查看:92
本文介绍了如何在DataGrid中显示分组数据? -摘要行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上了这堂课:

public enum KindOfPerson
{
    Student, Teacher, ...
}

public class Person
{
    // This contains only numbers between 0 and 1
    public double ScorePercent { get; set; }
    public KindOfPerson Type { get; set; }
}

我有一个人员列表,然后应用此LINQ函数或获得另一个由KindOfPerson分类的列表,并计算属于该KindOfPerson的所有人员的平均得分:

I have a people list and then I apply this LINQ function ot get another list which is classified by KindOfPerson and calculates the average score of all the people belong to that KindOfPerson:

var groupedLists = peopleList.GroupBy(person => person.Type)
                         .OrderBy(group => group.Key)
                         .Select(group => new {
                             People = group.ToList(),
                             AverageScore = group.Average(p => p.ScorePercent)
                          })
                          .ToList();

我不想在DataGrid中显示此列表,但我不知道要这样做.

I'd like t show this list in a DataGrid but I don't have any idea to do it.

我正在尝试这样做:

[DATAGRID]

[DATAGRID]

学生平均得分:XXX

Student AVERAGE SCORE: XXX

  • SCORE PERCENT 1

  • SCORE PERCENT 1

SCORE PERCENT 2

SCORE PERCENT 2

教师平均评分:YYY

Teacher AVERAGE SCORE: YYY

  • SCORE PERCENT 1

  • SCORE PERCENT 1

SCORE PERCENT 2

SCORE PERCENT 2

那样的事情,发牢骚.

更新

我认为这段代码可以帮助我们: http://leeontech.wordpress.com/2010/02/01/summary-row-in-datagrid/

I think this code can help us: http://leeontech.wordpress.com/2010/02/01/summary-row-in-datagrid/

推荐答案

此处,您会发现有关如何使用DataGrid进行分组的示例. 此处是有关如何实施分组.

Here you find an example on how grouping is done with the DataGrid. Here is another link on how implement grouping.

主要是像在所有可分组的WPF控件中一样进行操作.但是请注意,如果使用分组功能,则DataGrid会失去UI虚拟化的功能.因此,通常不是 用分组数据创建巨大列表的好主意.

Principally it's done like in all groupable WPF-controls. However be aware that DataGrid loose the capability of UI virtualization if you use grouping functionality. Therefore it is generally not a good idea to create huge lists with grouped data.

对于模型,建议您创建用于每个订单项的视图模型.该VM提供所有必要的属性,例如ScorePercent1,ScorePercent2以及分组标题.

For the model, I recommend that you create a view-model that is used for each line item. This VM provides all neceessary properties such as ScorePercent1, ScorePercent2 and also the grouping title.

这篇关于如何在DataGrid中显示分组数据? -摘要行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆