Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display properties of child object in Datagridview

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.

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.

So example code:

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

Hence, I want the table to show columns: Score, Name, UserName


EDIT: 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
like image 880
bretddog Avatar asked Jan 01 '26 08:01

bretddog


2 Answers

You can use databinding here, if you use the ITypedList interface to expose the properties you wanted.

ITypedList is very powerful, but somewhat hard to understand, IME. The best tutorial I've found is Tips for binding grids to hierarchical data using the ITypedList interface

like image 137
Tom Bushell Avatar answered Jan 06 '26 03:01

Tom Bushell


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
like image 36
bretddog Avatar answered Jan 06 '26 04:01

bretddog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!