HI,
based on your other questions, I have created a demo that shows properties and values of an object in a DataGridView. In addition, the properties have attributes that are displayed as an additional column.
Imports System.ComponentModel
Imports System.Reflection
Public Class Form1
Private dgv As New DataGridView With {.Dock = DockStyle.Fill, .AutoGenerateColumns = True}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Controls.Add(dgv)
'
Dim s As New Sample
'
dgv.DataSource = New PropertyList(s)
End Sub
Private Class PropertyList
Inherits List(Of PropertyItem)
Public Sub New(obj As Object)
For Each prop In obj.GetType().GetProperties(BindingFlags.Public Or BindingFlags.Instance)
Me.Add(New PropertyItem(obj, prop))
Next
End Sub
End Class
Public Class PropertyItem
Public Sub New(obj As Object, prop As PropertyInfo)
Me._obj = obj
Me._prop = prop
End Sub
Private _obj As Object
Private _prop As PropertyInfo
Public ReadOnly Property ID As String
Get
Return Me._prop.Name
End Get
End Property
Public ReadOnly Property Question As String
Get
For Each att As CustomAttributeData In Me._prop.CustomAttributes
Dim args = att.ConstructorArguments
If args.Count > 0 Then Return args(0).ToString.Substring(1, args(0).ToString.Length - 2)
Next
Return String.Empty
End Get
End Property
Public Property Answer As Object
Get
Return Me._prop.GetValue(Me._obj)
End Get
Set(value As Object)
Me._prop.SetValue(Me._obj, value)
End Set
End Property
End Class
Public Class Sample
<Description("Question 1")> Public Property Q1 As String
<Description("Question 2")> Public Property Q2 As String
End Class
End Class
Result: