展平集合的集合以便在 WPF 数据网格上显示
我正在 Telerik WPF 数据网格上使用堆叠标头。我解决这个问题的方法是创建数据的扁平化视图。例如。
它将显示如下:
Person A |乙 | 人C 人
月 |收入月份|收入月份|收入
我有一组人员,其中包含他们各自的月份和收入列表。
因此,我想让每个人处于同一水平,或者用更简单的术语来说,我想创建一个列表,其中水平显示所有月份和收入。 解决这个问题的最佳方法是什么?
I am working with stacked headers on a Telerik WPF data grid. The way I was approaching the problem was to create a flattened view of my data. For example.
it would display like the following:
Person A | Person B | Person C
Month | Earning Month|Earning Month|Earning
I have a collection of persons containing their respective lists of months and earning.
Therefore I want to bring each person on the same level or in easier terms, I want to create a single list with all the months and earnings available horizontally.
What would the best way to approach this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您是否想要一个包含多次的人员的列表,或者只是包含收入的列表。我根据不同的要求和我对您的类结构所做的猜测,为您提供了几个解决方案。
首先假设您想要一个列表,其中每个项目都有一个人、月份和收入,并且您有一个人员类的结构,其中包含两个列表(一个用于收入,一个用于在索引上同步的月份),您可以使用以下用于创建枚举的 LINQ 查询的变体
如果您只需要给出相同结构的月份和金额,您可以编写以下内容:
如果您有一个人员列表,其中的收入对象与月份和金额相匹配你可以写这样的东西:
或者,如果你不想要你要使用的人:
我希望其中之一就是你正在寻找的人,否则请进一步澄清你的问题,因为我误解了。
I am unsure if you want a list that has the people in it multiple times or just the list with the earnings. I give you a couple solutions based upon the differing requirements and the guesses that I had to make about your class structure.
First assuming you want a list of where each item has a person, the month, and the earnings and you have the structure of a person class with two contained lists (one for earnings and one for months that are synchronized on indexes you can use a variant of the following LINQ query to create the enumeration
If instead you wanted just the month and amounts given the same structure you'd write the following:
If instead you had a list of persons that has an earnings object which matches the month and the amount you could write something like this:
Or again if you didn't want the person you'd use:
I hope one of those is what you were looking for, otherwise please clarify your question further because I misunderstood.
正如其他人所说,如果不查看更多代码,就很难具体说明。但是,一般来说,扁平化集合是的事情SelectMany() LINQ 扩展方法 就是为此而设计的。
As others have said, it's difficult to be specific without seeing more of your code. But, in general, flattening collections is the sort of thing that the SelectMany() LINQ extension method is made for.