.NET 设计时数据源(用于组合框)

发布于 2024-07-10 07:35:10 字数 1152 浏览 5 评论 0原文

我正在尝试创建一个 ObjectDataSource,我可以用它绑定到 BindingSource,而 BindingSource 又应该绑定到 ComboBox。

我已经为该类创建了一个简单的类和一个简单的列表(见下文)。Times

  1. 列表类没有显示在我的工具箱中,因此我无法将其拖到表单中,以便我可以选择它作为绑定源的数据源。
  2. 第二个选项是创建一个新的项目数据源 (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)

  1. 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.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空心空情空意 2024-07-17 07:35:10

要改善 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.

挽清梦 2024-07-17 07:35:10

我可以将 System.ComponentModel.DataObject 属性添加到 class 中。 但是,我无法将 System.ComponentModel.DataObjectMethod 添加到我的 Display/Value 属性。 当我将它们更改为 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

I can add the System.ComponentModel.DataObject attribute to the class. However I cannot add a System.ComponentModel.DataObjectMethod to my Display/Value property. When I change them to Functions I get the following error:

'Overload resolution failed because no accessible New() accepts this number of arguments'

'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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文