例如,我使用一个简单的数据类
Public Class Alert
Private _dateEntered As String
Private _dateClosed As String
<DisplayName("Date Entered")>
Public Property DateEntered As String
Get
Return _dateEntered
End Get
Set(value As String)
_dateEntered = value
End Set
End Property
<DisplayName("Date Closed")>
Public Property DateClosed As String
Get
Return _dateClosed
End Get
Set(value As String)
_dateClosed = value
End Set
End Property
End Class
如果我将DataGridView作为项目数据源绑定到该对象,则尊重DisplayName属性,并且网格中的列具有正确的文本。
现在我列出警报列表
Public Class Alerts
Private _alerts As List(Of Alert)
Public Property Alerts As List(Of Alert)
Get
Return _alerts
End Get
Set(value As List(Of Alert))
_alerts = value
End Set
End Property
End Class
现在,当将我的DataGridView作为项目数据源绑定到List对象时,将不使用DisplayName属性,并且网格中的列将没有文本。
是否可以通过列表将DisplayName属性传递给DataGridView列?