Hi,
you can use Reflection to get names and values of properties for displaying in Datagrid like in following demo:
Imports System.Reflection
Public Class Form10
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 PropertyName As String
Get
Return Me._prop.Name
End Get
End Property
Public ReadOnly Property PropertyValue As Object
Get
Return Me._prop.GetValue(Me._obj)
End Get
End Property
End Class
Public Class Sample
Public ReadOnly Property Prop1 As Integer = 1
Public ReadOnly Property Prop2 As Integer = 2
End Class
End Class