.NET Designtime Datasource (for Combobox)
Asked Answered
P

2

0

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
Potion answered 11/12, 2008 at 11:47 Comment(0)
P
0

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
Potion answered 11/12, 2008 at 12:34 Comment(1)
DataObjectMethod has no parameterless constructors, add a System.ComponentModel.DataObjectMethodType.Molasses
E
0

To improve the experience with ObjectDataSource, consider marking your data-types with [DataObject]. Also, there is a [DataObjectMethod] attribute that defines the operations possible.

Exhortative answered 11/12, 2008 at 12:22 Comment(0)
P
0

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
Potion answered 11/12, 2008 at 12:34 Comment(1)
DataObjectMethod has no parameterless constructors, add a System.ComponentModel.DataObjectMethodType.Molasses

© 2022 - 2024 — McMap. All rights reserved.