2016-01-20 129 views
0

我編寫了一個類,並希望它的屬性在DataGridView控件中顯示。但是,只有一些屬性可用於綁定到列。我如何使所有公共屬性都可以綁定到列?以下是我的課程,IndividualServices屬性沒有出現在設計師中,而其他人則是。將自定義類的屬性綁定到WinForms DataGridView

Public Class Patient 
Private _name As String 
Private _id As String 
Private _services As New List(Of Service) 


Property Name As String 
    Get 
     Return _name 
    End Get 
    Set(value As String) 
     _name = value 
    End Set 
End Property 
Property ID As String 
    Get 
     Return _id 
    End Get 
    Set(value As String) 
     _id = value 
    End Set 
End Property 
Public ReadOnly Property Services As List(Of Service) 
    Get 
     Return _services 
    End Get 
End Property 
ReadOnly Property TotalServices As Integer 
    Get 
     Dim i As Integer = 0 
     For Each s As Service In _services 
      i = i + s.Count 
     Next s 
     Return i 
    End Get 

End Property 
ReadOnly Property IndividualServices As Integer 
    Get 
     Return _services.Count 
    End Get 
End Property 

Public Sub Add(sName As String, sCode As String) 
    Dim bool As Boolean = False 
    If _services.Count = 0 Then GoTo firstThrough 
    For Each s As Service In _services 
     If s.Name = sName Then 
      s.Add(1) 
      bool = True 
      Exit For 
     End If 
    Next 
    If Not bool Then 
firstThrough: 
     Dim newSer As New Service 
     newSer.Name = sName 
     newSer.Code = sCode 
     newSer.Count = 1 
     _services.Add(newSer) 
    End If 
End Sub 
End Class 
+0

你到目前爲止嘗試過的所有東西?你有沒有試過返回「_services.Count」而不是「Services.Count」? – Andarta

+0

設計師沒有改變,但感謝您指出了這一點!進行編輯。我將它添加爲僅用於DataGridView的屬性,否則我一直在調用Patient.Services.Count – aitchpat

+1

Off-Topic,但強烈建議:避免使用「GoTo」語句。 –

回答

0

原來,清理和重建解決方案解決了我的問題!將來會更頻繁地採取這些措施。

相關問題