在VB.Net中,我想将List <type>的列名绑定到DataGridView的列名。

时间:2018-12-14 11:23:38

标签: .net vb.net datagridview

例如,我使用一个简单的数据类

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列?

0 个答案:

没有答案