.NET Designtime Datasource (for Combobox)

I'm trying to create an ObjectDataSource that I can use to bind to a BindingSource, which in turn needs to bind to a ComboBox.

I created a simple class and a simple list for this class (see below)

  • The Times list class does not appear in my toolbar, so I cannot drag it into the form, so I can select it as the data source for the binding source.
  • The second option is to create a new project data source (ObjectDataSource). Here you are prompted to "select the object you want to bind to". I've added a friend / public / private variable to Form1 that instantiates the Times class. However, this variable is not displayed. The only object that 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

      

0


source to share


2 answers


I can add an attribute System.ComponentModel.DataObject

to class

. However, I cannot add System.ComponentModel.DataObjectMethod

to mine Display/Value property

. When I change them to Functions

I get the following error:

'Failed to overload because available New()

does not take 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

      

0


source


To improve your experience with ObjectDataSource

, consider labeling your data types with [DataObject]

. In addition, there is an attribute [DataObjectMethod]

that defines the possible operations.



0


source







All Articles