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
你到目前为止尝试过的所有东西?你有没有试过返回“_services.Count”而不是“Services.Count”? – Andarta
设计师没有改变,但感谢您指出了这一点!进行编辑。我将它添加为仅用于DataGridView的属性,否则我一直在调用Patient.Services.Count – aitchpat
Off-Topic,但强烈建议:避免使用“GoTo”语句。 –