我正在尝试创建一个ObjectDataSource,我可以用它绑定到一个BindingSource,然后绑定到一个ComboBox。
我为这个类创建了一个简单的类和一个简单的列表(见下文)
我错过了什么?
Public Class Time
Private _timeValue As String
Private _timeDisplay As String
Public Sub New(ByVal Value As String, ByVal Display As String)
Me._timeDisplay = Display
Me._timeValue = Value
End Sub
Public Property Display() As String
Get
Return Me._timeDisplay
End Get
Set(ByVal value As String)
Me._timeDisplay = value
End Set
End Property
Public Property Value() As String
Get
Return Me._timeValue
End Get
Set(ByVal value As String)
Me._timeValue = value
End Set
End Property
End Class
Public Class Times : Inherits List(Of Time)
Public Sub New()
End Sub
End Class
答案 0 :(得分:0)
要改善ObjectDataSource
的使用体验,请考虑使用[DataObject]
标记数据类型。此外,还有[DataObjectMethod]
属性定义了可能的操作。
答案 1 :(得分:0)
我可以将System.ComponentModel.DataObject
属性添加到class
。但是,我无法向System.ComponentModel.DataObjectMethod
添加Display/Value property
。当我将它们更改为Functions
时,我收到以下错误:
'重载解析失败,因为没有可访问的New()
接受此数量的参数'
'This works
<System.ComponentModel.DataObject()> _
Public Class Time
Private _timeValue As String
Private _timeDisplay As String
Public Sub New()
End Sub
Public Sub New(ByVal Value As String, ByVal Display As String)
Me._timeDisplay = Display
Me._timeValue = Value
End Sub
'This doesn't work
<System.ComponentModel.DataObjectMethod()> _
Public Function getDisplay() As String
Return Me._timeDisplay
End Function
'This doesn't work
<System.ComponentModel.DataObjectMethod()> _
Public Function getValue() As String
Return Me._timeValue
End Function
End Class