views:

70

answers:

1

I have a custom UserControl that contains several child controls, amongst which is a DataGridView. I don't want to EnableDesignMode for any of the child controls, but instead have exposed and serialized their properties as needed. I'm stuck on DataGridView's DataSource property.

Do I need to make a custom UITypeEditor and use reflection to find all the BindingSource objects on the parent form for selection, or can I somehow invoke the built-in editor of this type? What type is the editor invoked when changing DataGridView's DataSource?

EDIT: Actually, the suggestion from Oliver did not quite work out. I did get the list of bindable objects in the property grid when I select my UserControl and after I chose a binding source, columns of bound dataset appeared on the grid, but columns of datagridview are not serialized to designer.cs after editing the Columns collection. However, if I build a custom ParentControlDesigner and EnableDesignMode for this datagridview, I can set the binding via it's DesignerVerb, and then the Columns collection is serialized after editing.

I exposed datagridview's Columns and DataSource properties in this way

[Editor(typeof(CollectionEditor), typeof(UITypeEditor))]
[Category("Grid")]
//[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public DataGridViewColumnCollection Columns
{
    get { return dgvListaBaza.Columns; }
}

[AttributeProvider(typeof(IListSource))]
[Browsable(true)]
[Category("Grid")]
public object DataSource
{
    get { return dgvList.DataSource; }
    set { dgvList.DataSource = value; }
}

What is the difference between the way DataSource is set when I click on the control's native designerverb and the one through exposed property? Both show the columns of the bindingSource in the grid after i choose a binding, but Columns don't get serialized in the latter case, as if there is something else I need to set when setting the DataSource.

Also, DesignerSerializationVisibility attribute on the exposed Columns makes no difference, and the column Names in the CollectionEditor are different depending on the way I set the DataSource (If it's set through native designerverb, then they are named SomeColumnDataGridViewTextBoxColumn, and if it's set through the property, then the Name property of each column is empty).

+1  A: 

Take a look at DataSource for User Control.

Oliver
[AttributeProvider(typeof(IListSource))] did the trick! Thanks.
dr.lijenjin
Actually, not quite.. see the edit please.
dr.lijenjin