.NET 设计时数据源(用于组合框)
我正在尝试创建一个 ObjectDataSource,我可以用它绑定到 BindingSource,而 BindingSource 又应该绑定到 ComboBox。
我已经为该类创建了一个简单的类和一个简单的列表(见下文)。Times
- 列表类没有显示在我的工具箱中,因此我无法将其拖到表单中,以便我可以选择它作为绑定源的数据源。
- 第二个选项是创建一个新的项目数据源 (ObjectDataSource)。 这里要求“选择您想要绑定的对象”。 我在 Form1 中添加了一个friend/public/private 变量,它实例化了 Times 类。 然而这个变量没有显示。 出现在我的项目命名空间中的唯一对象是 Form1。
我缺少什么?
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
i'm trying to create a ObjectDataSource which I can use to bind to a BindingSource which on his turn should be bound to a ComboBox.
I've created a simple class and a simple list for this class (see below)
- The Times list class is not showing up at my toolbox, so I cannot drag it to the form so I can select it as the datasource for a bindingsource.
- Second option is to create a new project datasource (ObjectDataSource). Here is asked to 'select the object your wish to bind to'. I've added a friend/public/private variable to Form1 which instantiates the Times class. However this variable does not show. The only object which appears in my project namespace is Form1.
What am I missing?
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要改善
ObjectDataSource
的体验,请考虑使用[DataObject]
标记您的数据类型。 此外,还有一个[DataObjectMethod]
属性定义了可能的操作。To improve the experience with
ObjectDataSource
, consider marking your data-types with[DataObject]
. Also, there is a[DataObjectMethod]
attribute that defines the operations possible.我可以将
System.ComponentModel.DataObject
属性添加到class
中。 但是,我无法将System.ComponentModel.DataObjectMethod
添加到我的Display/Value 属性
。 当我将它们更改为Functions
时,出现以下错误:“重载解析失败,因为没有可访问的
New()
接受此数量的参数”I can add the
System.ComponentModel.DataObject
attribute to theclass
. However I cannot add aSystem.ComponentModel.DataObjectMethod
to myDisplay/Value property
. When I change them toFunctions
I get the following error:'Overload resolution failed because no accessible
New()
accepts this number of arguments'