When you use the VS2005 Windows Forms designer to edit any control, it has '(DataBindings)' section under the 'Data' category in the Properties browser.
I'm developing a custom control and would like to add design-time support for a property. I'd like my property to have the same design-time editor that the (DataBindings) properties use (ie. SelectedValue and SelectedItem for a ComboBox). I want the developer to be able to select (for example) a DataTable AND also a DataColumn at the same time. I am aware of how to add design-time support such as:
[
AttributeProvider(typeof(IListSource))]public object DataSource...
[
Editor("System.Windows.Forms.Design.DataMemberListEditor", typeof(UITypeEditor))]public string DataMember...
The problem is that the above only allow you to select a DataTable OR a DataColumn, but not both at the same time.
Does anyone have any idea which [Editor] atribute I should use for my property
Many thanks,
Ben S.

VS2005 Designer Question
Greg D Clark
I found the answer - it's DesignBindingEditor! Use the following attribute:
[
Editor("System.Windows.Forms.Design.DesignBindingEditor", typeof(UITypeEditor))]public new object SelectedValue...
Are these editors documented anywhere Only the public editors exposed by System.Windows.Forms.Design are mentioned on MSDN, not the internal ones which can also be very useful.
Ben S.
Joannes Vermorel - MSP
I've done it using Reflection:
private object m_SelectedValue;
TypeConverter("System.Windows.Forms.DesignBindingConverter")][
[Editor("System.Windows.Forms.Design.DesignBindingEditor", typeof(UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public object SelectedValue
{
get { return m_SelectedValue; }
set
{
object designBinding = value;
Type designBindingType = designBinding.GetType();
PropertyInfo dataSourceProperty = designBindingType.GetProperty("DataSource");
PropertyInfo dataMemberProperty = designBindingType.GetProperty("DataMember");
object dataSource = dataSourceProperty.GetValue(m_SelectedValue, null);
string dataMember = dataMemberProperty.GetValue(m_SelectedValue, null);
//...do something with dataSource and dataMember here...
}
}
DesignBinding also has another property called IsNull that you might want to use. I'd rather not use reflection, but I don't see any other choice. Hope this helps someone else too.
Ben S.
sandeep437
OK - not quite that simple.
Using the following attributes on my property doesn't work:
[
TypeConverter("System.Windows.Forms.Design.DesignBindingConverter")][Editor("System.Windows.Forms.Design.DesignBindingEditor", typeof(UITypeEditor))]
public object MyProperty...
Problem is, a System.Windows.Forms.Design.DesignBinding property is returned and it is protected internal so it cannot be used outside of Microsoft!
Does anyone have any idea how I can utilize the returned DesignBinding object
Many thanks,
Ben S.