问题描述
如何在datagridview中显示选定的对象的属性,以及此第一个对象的成员对象的选定属性?我认为我不需要绑定,但依靠硬编码更新,因为更新将在非UI线程上启动,我认为绑定不会那么容易。至少我在其他项目中遇到了问题。
How can I display in a datagridview selected properties of an object, and also selected properties of a member object of this first object? I think I will not require binding but rely on hard coding updates, because the updates will initiate on non-UI threads, and I think that will not be so easy to bind. At least I've had problems with that in other project.
基本上我正在想知道我可以做什么不同的方式。也许LINQ,或任何最适合的。注意:我想在同一张表中显示数据。因为孩子/父母是1:1的关系。
Basically I'm looking to understand what different ways I can do this. Maybe with LINQ, or whatever is most suitable. Note: I want to display the data in the same table. As the child/parent is a 1:1 relation.
所以示例代码:
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
Hence, I want the table to show columns: Score, Name, UserName
编辑:
哦,这比我想象的更容易,将工作:
Oh, this was more easy than I thought, seems this will work:
Dim q = (From n in userList Select New With {n.Score, n.Details.Name, n.Details.userName}).ToArray
推荐答案
,这看起来像是适当的解决方案:
For the record, this looks like appropriate solution:
Dim q = (From n in userList Select New With {n.Score, n.Details.Name, n.Details.userName}).ToArray
这篇关于在Datagridview中显示子对象的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!