Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataSource for User Control

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;
        }
    }
like image 852
Khadaji Avatar asked Jan 25 '09 21:01

Khadaji


1 Answers

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))]
like image 114
Marc Gravell Avatar answered Sep 29 '22 15:09

Marc Gravell