Domanda

sto cercando di creare un ObjectDataSource che posso usare per legarsi ad un BindingSource, che nel suo turno dovrebbe essere associato a una casella combinata.

Ho creato una semplice classe e un elenco semplice per questa classe (vedi sotto)

  1. La classe lista tempi non viene visualizzato alla mia casella degli strumenti, quindi non posso trascinarlo alla forma in modo da poter selezionare come l'origine dati per un BindingSource.
  2. La seconda opzione è quella di creare una nuova origine dati di progetto (ObjectDataSource). Qui è chiesto di 'selezionare l'oggetto vostro desiderio di legarsi a'. Ho aggiunto un amico / public / variabile privata a Form1 che crea un'istanza della classe Times. Tuttavia questa variabile non mostra. L'unico oggetto che compare nel mio progetto namespace è Form1.

Che cosa mi manca?

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
È stato utile?

Soluzione 2

Posso aggiungere l'attributo al System.ComponentModel.DataObject class. Tuttavia non posso aggiungere una System.ComponentModel.DataObjectMethod al mio Display/Value property. Quando cambio loro di Functions ricevo il seguente errore:

'risoluzione di sovraccarico non riuscita perché non accessibili New() accetta questo numero di argomenti'

'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

Altri suggerimenti

Per migliorare l'esperienza con ObjectDataSource, prendere in considerazione la marcatura tuoi tipi di dati con [DataObject]. Inoltre, v'è un [DataObjectMethod] attributo che definisce le operazioni possibili.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top