views:

931

answers:

2

I am buidling a user control. Currently it consists of a textbox and a button - as a learning experience. This will be used as a basis for a more useful control.

I want to add a DataSource, display member and ValueMember.
Here is my code for the datasource. It will display in the Properties editor, but is disabled and grayed out. What am I missing?

    private object MyDataSource;

    [Browsable(true)]
    [TypeConverter("System.Windows.Forms.Design.DataSourceConverter")]
    [System.ComponentModel.Bindable(true)]
    public object DataSource
    {
        get
        {
            return MyDataSource;
        }
        set
        {
            if (MyDataSource != value)
                MyDataSource = value;
        }
    }
+2  A: 

An easier option may be to use an attribute provider instead:

[AttributeProvider(typeof(IListSource))]

You could try using the assembly-qualified name? and specifying the editor?

[TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[Editor("System.Windows.Forms.Design.DataSourceListEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]

Actually, you can abbreviate this to be version-independent just by specifying the assembly:

[TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design")]
[Editor("System.Windows.Forms.Design.DataSourceListEditor, System.Design", typeof(UITypeEditor))]
Marc Gravell
A: 

[AttributeProvider(typeof(IListSource))]

Seems to be the correct answer - thank you.

Khadaji