Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27020

DataGridView databinding custom object containing list of custom objects?

$
0
0
Hi VBForums, every time I ask a question on here I get quality replies so I have one quick one for anyone reading...

I have a custom class called TestObject, containing a List Of(TestObject2), and a few other base type Properties. Check the below example code before reading on..

Code:

Public Class TestObject
Public Property OtherObjectsList As List(Of TestObject2)
Public Property Name As String
Public Property Gender As String
Public Property Age As Integer
End Class

Public Class TestObject2
Public Property TestName As String
Public Property URL As String
Public Property IsValid As Boolean

Public Sub New(testName As String, url As String)
Me.TestName = testname
Me.URL = url
End Sub

Public Sub CheckValidity()
'Send a HTTP Webrequest to the URL, if the request returns a valid response, set the IsValid property to True.
End Sub

End Class

So, If I bind a List(Of TestObject) to a BindingSource, and then to a DataGridView DataSource which has it's AutoGenerateColumns property set to True, the DGV will only make columns for the Name, Gender, and Age public properties of TestObject.

However, I want each TestObject2 in the OtherObjectsList property in TestObject to also be included in the DataGridView. How can I achieve this? Do I have to use mixed mode with my DGV (Having some columns databound, and some not.) I would like to avoid that if possible.

Viewing all articles
Browse latest Browse all 27020

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>