This is not a dependable solution because next time you add another instance of that control to the page, it happens again.
Here is my code :
[LookupBindingProperties("DataSource", "DisplayMember", "ValueMember", "SelectedValue")]
public partial class BaseLookupControl : BaseUserControl
{
public BaseLookupControl()
{
InitializeComponent();
}
private string myDisplayMember;
[DefaultValue("")]
public string DisplayMember
{
get { return myDisplayMember; }
set
{
myDisplayMember = value;
OnDisplayMemberChanged(new EventArgs());
}
}
public event EventHandler DisplayMemberChanged;
protected virtual void OnDisplayMemberChanged(EventArgs e)
{
if (DisplayMemberChanged != null)
{
DisplayMemberChanged(this, e);
}
}
private string myValueMember;
[DefaultValue("")]
public string ValueMember
{
get { return myValueMember; }
set
{
myValueMember = value;
OnValueMemberChanged(new EventArgs());
}
}
public event EventHandler ValueMemberChanged;
protected virtual void OnValueMemberChanged(EventArgs e)
{
if (ValueMemberChanged != null)
{
ValueMemberChanged(this, e);
}
}
private object myDataSource;
[DefaultValue("")]
[AttributeProvider(typeof(IListSource))]
[RefreshProperties(RefreshProperties.All)]
public object DataSource
{
get { return myDataSource; }
set
{
myDataSource = value;
OnDataSourceChanged(new EventArgs());
}
}
public event EventHandler DataSourceChanged;
protected virtual void OnDataSourceChanged(EventArgs e)
{
if (DataSourceChanged != null)
{
DataSourceChanged(this, e);
}
}
private string myDataMember;
[RefreshProperties(RefreshProperties.All)]
[Editor("System.Windows.Forms.Design.DataMemberListEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
[DefaultValue("")]
public string DataMember
{
get { return myDataMember; }
set
{
myDataMember = value;
OnDataMemberChanged(new EventArgs());
}
}
public event EventHandler DataMemberChanged;
protected virtual void OnDataMemberChanged(EventArgs e)
{
if (DataMemberChanged != null)
{
DataMemberChanged(this, e);
}
}
private string mySelectedValue;
public event EventHandler SelectedValueChanged;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
[Bindable(true)]
[DefaultValue("")]
public string SelectedValue
{
get { return mySelectedValue; }
set
{
mySelectedValue = value;
OnSelectedValueChanged(new EventArgs());
}
}
protected virtual void OnSelectedValueChanged(EventArgs e)
{
if (SelectedValueChanged !=null)
{
SelectedValueChanged(this, e);
}
}
private void BaseLookupControl_Load(object sender, EventArgs e)
{
}
}
I have copied most of it from the Meta information of "LISTBOX" control.
Listbox does not have "DesignerSerializationVisibility.Hidden" or "DesignerSerializationVisibility.Content" attribute on the Datasource property.
However, when I drop this control on my form I get "DataSource of controlxyz is null. This is not allowed" error message (Yes, a popup error message on the designer).
Even if I set the DataSource of this control to a dataset on my form, that error keeps popping up.
If I add an attribute "DesignerSerializationVisibility.Content" or "DesignerSerializationVisibility.Hidden", then the designer does not gererate code in the designer file. I tried BOTH of the settings, yields the same result. I was expecting it to WRITE CODE i nthe designer file with the "CONTENT" setting, but not serialize it in the resX file...
Can you please give a clear description of the designer serialization attribute values, and the designer.cs (or vb for that matter) and resx behavior ?
Please correct me if I am wrong: on http://msdn2.microsoft.com/en-us/library/system.componentmodel.designerserializationvisibility.aspxit says
|
Member name |
Description |
|
Content |
The code generator produces code for the contents of the object, rather than for the object itself. |
|
Hidden |
The code generator does not produce code for the object. |
|
Visible |
The code generator produces code for the object. |
There is NOTHING about the serialization in the resX file there...
But I assume "rather than the object itself" means "the object will not be serialized in the RESX file" there.
Please suggest