    <Category("MyUserControl Data"), _
    Description("Set DataSource DisplayMember"), _
    Editor(GetType(System.Web.UI.Design.DataFieldConverter), _
    GetType(System.Drawing.Design.UITypeEditor)), _
    RefreshProperties(RefreshProperties.Repaint)> _
    Public Property DisplayMember() As String
        Get
            Return ComboMultiColumn.DisplayMember
        End Get
        Set(ByVal Value As String)
            ComboMultiColumn.DisplayMember = Value
        End Set
    End Property

    <Category("MyUserControl Data"), _
    Description("Set DataSource ValueMember"), _
    Editor(GetType(System.Web.UI.Design.DataFieldConverter), GetType(System.Drawing.Design.UITypeEditor)), _
    RefreshProperties(RefreshProperties.Repaint)> _
    Public Property ValueMember() As String
        Get
            Return ComboMultiColumn.ValueMember
        End Get
        Set(ByVal Value As String)
            ComboMultiColumn.ValueMember = Value
        End Set
    End Property


http://blog.ellipsi.com/2004/06/designer-aware-controls.html


 I've been working on UserControl that include several internal controls like usercontrols typically does. One internal control is ComboBox which members I have hided. However there are some propertys that i wanted to expose example Databinding related propertys like DataSource, DisplayMember and ValueMember. I was little confused about how to enable those special type of propertys to Visual Studio's propertypage, in other words how to create them to support designer same way like combobox same propertys do.
Well yes, Editor-attribute I was familiar with. I've been used that for Image-type property and some other that needs own type of editor for designer support.
As we know ComboBox inherit from ListControl and it can display diverse types of objects.
In not so deeper analysis of DisplayMember or ValueMember properies tells that they are not so special but just Strings. What i needed was good Designer support and association to DataSource property. And how to make that happend?

I have simplified codesnippet that sets properties direct to internal ComboBox in my UserControl:



Public Property DataSource() As Object
Get
Return Me.ComboBox1.DataSource
End Get
Set(ByVal Value As Object)
ComboBox1.DataSource = Value
End Set
End Property

Public Property DisplayMember() As String
Get
Return ComboBox1.DisplayMember
End Get
Set(ByVal Value As String)
ComboBox1.DisplayMember = Value
End Set
End Property

Public Property ValueMember() As String
Get
Return ComboBox1.ValueMember
End Get
Set(ByVal Value As String)
ComboBox1.ValueMember = Value
End Set
End Property



That works fine but im not yet in goal. There is no any support for designer and because Datasource is Object type the Designer disable it totally.
First I type some attributes to DataSource property:

RefreshProperties(RefreshProperties.Repaint), _
TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design")>

Category and description for propertypage, Refreshing associated propertys when property changes and last but not the least attribute will be TypeConverter with DataSourceConverter class to providing methods that can be used to retrieve a list of data sources accessible to the current design-time component.

No we see that Designer propertypage lists all datasources available to UserControl's DataSource property but DisplayMember and ValueMember has no any relations to it...yet.

Next task is to make relations to rest two property (DisplayMember and to ValueMember).
This maybe trivial issue to many and also Google tells we lot of things but i will goto this anyway.

So I wanted DisplayMember and ValueMember to act like a List in Designer but as an property in my UserControl they should still be String type like ComboBox do. Again I have to add some attributes to both properties.


Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design", GetType(System.Drawing.Design.UITypeEditor)), _
RefreshProperties(RefreshProperties.Repaint)>

First two attributes will be again category and description. Third attribute "Editor" we need to specifying the editor to change a property in designer.
When editing the property, a visual designer should create a new instance of the specified editor through a drop-down window.
Editor attribute's first parameter could be string that tells Designer used editor fully qualified type name or it also could be type of editor. Both way we could tell Designer that what Editor it should render.
Second parameter is baseType that is used as a key to find a particular editor for designer use, in this case and many other cases as well then base type is UITypeEditor. And last we could use RefreshProperties attribute if there are some properties asociated to current property.
Instead of DataMemberFieldEditor that intellisense does not surely show we could select right editor type from System.Web.Ui.Design.DataFieldConverter so Editor attribute will be then
Editor(GetType(System.Web.Ui.Design.DataFieldConverter), GetType(System.Drawing.Design.UITypeEditor)) However, That needs System.Designer and System.Web reference to project so it is matter of taste which one way to specify Editor will be used.

And there are final code that is truly Designer aware:


<Category("MyUserControl Data"), _
Description("Set Datasource for combobox"), _
RefreshProperties(RefreshProperties.Repaint), _
TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design")> _
Public Property DataSource() As Object
Get
Return Me.ComboBox1.DataSource
End Get
Set(ByVal Value As Object)
ComboBox1.DataSource = Value
End Set
End Property

<Category("MyUserControl Data"), _
Description("Set DataSource DisplayMember"), _
Editor(GetType(System.Web.Ui.Design.DataFieldConverter), _
GetType(System.Drawing.Design.UITypeEditor)), _
RefreshProperties(RefreshProperties.Repaint)> _
Public Property DisplayMember() As String
Get
Return ComboBox1.DisplayMember
End Get
Set(ByVal Value As String)
ComboBox1.DisplayMember = Value
End Set
End Property

<Category("MyUserControl Data"), _
Description("Set DataSource ValueMember"), _
Editor(GetType(System.Web.Ui.Design.DataFieldConverter), GetType(System.Drawing.Design.UITypeEditor)), _
RefreshProperties(RefreshProperties.Repaint)> _
Public Property ValueMember() As String
Get
Return ComboBox1.ValueMember
End Get
Set(ByVal Value As String)
ComboBox1.ValueMember = Value
End Set
End Property


There is screen record about my sample control how it properties now interact with designer. In video there is one form with one usercontrol instance in it and I drag'n drop new dataset to it. After that I bind usercontrol to that dataset with custom properties.
You can watch it here.

Ok, now my UserControl have better designer support for datasource. This is just good start and further, there are interfaces for implementing very own UI type editors for designer and I will wrote some better words about that later.
