【问题标题】:howto create dynamic gridview in a listview item in wpf如何在 wpf 的列表视图项中创建动态网格视图
【发布时间】:2025-12-08 17:35:01
【问题描述】:

情况是这样的:

我有一个包含一些项目的列表视图。这些项目中的每一个都有另一个列表,我想在网格视图中显示这个列表。

所以我想用扩展器显示主列表视图,如果用户展开其中一项,它将在网格视图中显示另一个列表。

问题是,gridview必须是动态的,因为item的属性是动态的。

您能否给我一些想法,如何在列表视图项中创建具有动态列的网格视图。

有一个插图 :D :

带有扩展器的主列表:

->mainitem1
->mainitem2(这是扩展的:))

 Column1   Column2  Column3
property1 property2 property3   (other list first item properties)
property1 property2 property3   (other list second item properties)
property1 property2 property3   (other list third item properties)
property1 property2 property3   (other list fourth item properties)

->mainitem3

希望你能理解 :) .

提前感谢您的每条评论!

问候, 佐利

【问题讨论】:

    标签: c# wpf gridview


    【解决方案1】:

    我建议使用 wpf DataGrid。

    您可以将它用于整个解决方案,或者只是内部 ListView 可以是 DataGrid。 DataGrid 可以自动为您生成列,您可以将其设置为只读,使其行为类似于 ListView。

    【讨论】:

    • 谢谢,它解决了我的问题,但我必须创建 AutoGeneratedColumn 事件,因为我的属性在列表中,并且我必须在代码隐藏中动态地将列添加到数据网格中。
    最近更新 更多