在 ListView 中对组进行分组

发布于 12-31 22:05 字数 125 浏览 2 评论 0原文

我有一个项目集合,每个项目都位于某些组中。 我在 WPF 列表视图中显示集合,并希望按组进行分组,但这是不可能的,因为我有一个 IEnumerable :-)。并且一行必须不仅出现一次。

有人知道我该如何解决这个问题吗?

I have a collection of items, and every item is in some groups.
I show the collection in a WPF Listview and want to group by the groups, but that is not possible becuase i have a IEnumerable :-). And a row has to show up not only once.

Does anybody have an idea how i can solve this problem ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多情出卖2025-01-07 22:05:11

您可以将 DataTemplate 用于内部项目,并在内部数据模板内使用另一个列表视图来显示该组项目。

You can use DataTemplate for the inner item and inside the inner data template another Listview can be used to display that group items.

波浪屿的海角声2025-01-07 22:05:11

最好使用 TreeViewHierarchicalDataTemplate 显示您的分组级别数据结构。

我不知道你的数据结构到底是什么样的。如果您已经扁平化数据,您可能需要将这种数据结构更改

public class Item 
{
    public string Group { get; set; } // A prop you want the grouping on
    public string AnotherItemProp { get; set; } 
}

public IEnumerable<Item> Items // used as your list source somewhere

为:

public class Group
{
    public string AnotherGroupProp { get; set; } // grouping value from flattened
    public IEnumerable<Item> Items { get; set; }
}

public class Item
{
    public string AnotherItemProp { get; set; }
}   

public IEnumerable<Group> Groups { get; set; } // Used by treeview

It's better to use a TreeView and a HierarchicalDataTemplate to show the grouping levels in your datastructure.

I don't know exactly what your data structure looks like. If you've flattened data you possibly need to change this kind of data structure

public class Item 
{
    public string Group { get; set; } // A prop you want the grouping on
    public string AnotherItemProp { get; set; } 
}

public IEnumerable<Item> Items // used as your list source somewhere

To this:

public class Group
{
    public string AnotherGroupProp { get; set; } // grouping value from flattened
    public IEnumerable<Item> Items { get; set; }
}

public class Item
{
    public string AnotherItemProp { get; set; }
}   

public IEnumerable<Group> Groups { get; set; } // Used by treeview
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文