gpt4 book ai didi

linq - 在 Datagridview 中显示子对象的属性

转载 作者:行者123 更新时间:2023-12-02 00:36:14 26 4
gpt4 key购买 nike

如何在数据 GridView 中显示对象的选定属性,以及第一个对象的成员对象的选定属性?我认为我不需要绑定(bind),而是依靠硬编码更新,因为更新将在非 UI 线程上启动,而且我认为绑定(bind)不会那么容易。至少我在其他项目中遇到过问题。

基本上,我想了解我可以通过哪些不同的方式来做到这一点。也许使用 LINQ,或者任何最合适的方法。注意:我想在同一个表中显示数据。由于 child / parent 是 1:1 的关系。

示例代码:

Public Class User
public property Score as Integer
public property Details as UserDetails
End Class

Public Class UserDetails
public property Name as String
public property userName as String
End Class

因此,我希望表格显示列:Score、Name、UserName


编辑:哦,这比我想象的要容易得多,看来这行得通:

Dim q = (From n in userList Select New With {n.Score, n.Details.Name, n.Details.userName}).ToArray

最佳答案

如果您使用 ITypedList 接口(interface)公开您想要的属性,则可以在此处使用数据绑定(bind)。

ITypedList 很强大,但是有点难懂,IME。我找到的最好的教程是 Tips for binding grids to hierarchical data using the ITypedList interface

关于linq - 在 Datagridview 中显示子对象的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4493412/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com