Hi kana250688,
I have verified your code. There is no issue in your code. Its working correctly.
RotatedListDataSource
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Linq
Public Class RotatedListDataSource(Of T)
Inherits List(Of RotatedItem)
Public ReadOnly Property List As List(Of T)
Public Sub New(ByVal list As List(Of T))
Me.List = list
Me.AddRange(GetType(T).GetProperties().Select(Function(p) New RotatedItem(p.Name, list.Cast(Of Object)().ToArray(), p.PropertyType)))
End Sub
End Class
Public Class RotatedItem
Inherits CustomTypeDescriptor
Public ReadOnly Property PropertyName As String
Private data() As Object
Public ReadOnly Property Type As Type
Public Sub New(ByVal propertyName As String, ByVal data() As Object, ByVal type As Type)
Me.PropertyName = propertyName
Me.data = data
Me.Type = type
End Sub
Public Overrides Function GetProperties() As PropertyDescriptorCollection
Return Me.GetProperties(New Attribute() {})
End Function
Public Overrides Function GetProperties(ByVal attributes() As Attribute) As PropertyDescriptorCollection
Dim properties = New List(Of PropertyDescriptor)()
properties.Add(New PropertyNameProperty(New Attribute() {New BrowsableAttribute(False)}))
For i As Integer = 0 To data.Length - 1
properties.Add(New IndexProperty(i, GetType(Object), New Attribute() {}))
Next i
Return New PropertyDescriptorCollection(properties.ToArray())
End Function
Default Public Property Item(ByVal i As Integer) As Object
Get
'Error below line Overload resolution failed because no accessible 'GetValue' accepts this number of arguments.
Return data(i).GetType().GetProperty(PropertyName).GetValue(data(i))
End Get
Set(ByVal value As Object)
'Error below line Overload resolution failed because no accessible 'SetValue' accepts this number of arguments.
data(i).GetType().GetProperty(PropertyName).SetValue(data(i), Convert.ChangeType(value, Type))
End Set
End Property
End Class
Public Class IndexProperty
Inherits PropertyDescriptor
Private index As Integer
Private type As Type
Public Sub New(ByVal index As Integer, ByVal type As Type, ByVal attributes() As Attribute)
MyBase.New(index.ToString(), attributes)
Me.index = index
Me.type = type
End Sub
Public Overrides ReadOnly Property ComponentType As Type
Get
Return GetType(RotatedItem)
End Get
End Property
Public Overrides ReadOnly Property IsReadOnly As Boolean
Get
Return False
End Get
End Property
Public Overrides ReadOnly Property PropertyType As Type
Get
Return type
End Get
End Property
Public Overrides Function CanResetValue(ByVal component As Object) As Boolean
Return False
End Function
Public Overrides Function GetValue(ByVal component As Object) As Object
Return DirectCast(component, RotatedItem)(index)
End Function
Public Overrides Sub ResetValue(ByVal component As Object)
End Sub
Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)
DirectCast(component, RotatedItem)(index) = value
End Sub
Public Overrides Function ShouldSerializeValue(ByVal component As Object) As Boolean
Return True
End Function
End Class
Public Class PropertyNameProperty
Inherits PropertyDescriptor
Public Sub New(ByVal attributes() As Attribute)
MyBase.New(NameOf(RotatedItem.PropertyName), attributes)
End Sub
Public Overrides ReadOnly Property ComponentType As Type
Get
Return GetType(RotatedItem)
End Get
End Property
Public Overrides ReadOnly Property IsReadOnly As Boolean
Get
Return True
End Get
End Property
Public Overrides ReadOnly Property PropertyType As Type
Get
Return GetType(String)
End Get
End Property
Public Overrides Function CanResetValue(ByVal component As Object) As Boolean
Return False
End Function
Public Overrides Function GetValue(ByVal component As Object) As Object
Return DirectCast(component, RotatedItem).PropertyName
End Function
Public Overrides Sub ResetValue(ByVal component As Object)
End Sub
Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)
End Sub
Public Overrides Function ShouldSerializeValue(ByVal component As Object) As Boolean
Return True
End Function
End Class
Code
Imports System.Reflection
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim list As List(Of Employee) = New List(Of Employee)()
list.Add(New Employee With {.Id = 1, .Name = "Mudassar Khan", .Country = "India"})
list.Add(New Employee With {.Id = 2, .Name = "John Hammond", .Country = "United States"})
'Set Data Source
dgv.DataSource = New RotatedListDataSource(Of Employee)(list)
'Hide Column Headers
dgv.ColumnHeadersVisible = False
'Set Row Headers Autosize
dgv.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders
'Show PropertyName on RowHeader
AddHandler dgv.RowPrePaint, Sub(o, a)
Dim value = CType(dgv.Rows(a.RowIndex).DataBoundItem, RotatedItem).PropertyName
If a.RowIndex > -1 AndAlso $"{dgv.Rows(a.RowIndex).HeaderCell.Value}" <> value Then
dgv.Rows(a.RowIndex).HeaderCell.Value = value
End If
End Sub
End Sub
Public Class Employee
Public Property Id As Integer
Public Property Name As String
Public Property Country As String
End Class
End Class
Screenshot