How to implement Complex DataBinding on Custom Controls?

Im building a custom control called DataEntry Control and want to be able to
setup a DataSource on property window, same way as DataGridView...

Here are some parts of my code:

<DefaultBindingProperty(""), ComplexBindingProperties("DataSource",
"DataMember")> _
Public Class DataEntryControl

    Private _DataSource As Object
    <Category("Data")> _
    Public Property DataSource() As Object
        Get
            Return _DataSource
        End Get
        Set(ByVal value As Object)
            _DataSource = value
            SetupControls()
        End Set
    End Property

    Private _DataMember As String
    <Category("Data")> _
    Public Property DataMember() As String
        Get
            Return _DataMember
        End Get
        Set(ByVal value As String)
            _DataMember = value
        End Set
    End Property

...

End Class


The DataSource and DataMember properties are being displayed on property
window, but DataSource is grayed out and instead of the ellipse button to
choose a DataSource, its being displayed a textbox to set the property
value. It seems that the right TypeEditor is not being used.

What am I missing

Thanks in advance.

Fernando



Answer this question

How to implement Complex DataBinding on Custom Controls?

  • DrNecessiter

    Add TypeConverter and EditorBrowsable attributes on your DataSource property (in addition to your Category attribute), as follows:

    <TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design")>
    <EditorBrowsable(EditorBrowsableState.Always)>
    <Category("Data")> _
    Public Property DataMember() As String
    Get
    Return _DataMember
    End Get
    Set(ByVal value As String)
    _DataMember = value
    End Set
    End Property




  • cnSZlzl

    I'm sorry, I think TypeConverter attribute must be added to DataSource Property and the attribute

    Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")

    must be added to DataMember property of the control


  • How to implement Complex DataBinding on Custom Controls?