How to save collection data in Design Time with Custom UITypeEditor C# WindowsFormApplication?
<p>I wrote my own UITypeEditor and I reached my goal with help of @Sefe and with <a href="https://stackoverflow.com/questions/5171037/display-list-of-custom-objects-as-a-drop-down-in-the-propertiesgrid/5181847">THIS</a> link. </p>

<p>My basic setup:
<a href="https://i.stack.imgur.com/Uqa0j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uqa0j.png" alt="My basic setup"></a></p>

<p>In this setup, <code>BaseForm</code> extends <code>System.Windows.Forms.Form</code>. Here i'm putting my property (<code>List&lt;Control&gt; ActionButtons</code>) that have a custom UITypeEditor like a modal style.</p>

<p><b>Resumed workflow (All here are in Design Time):</b></p>

<p>&nbsp;&nbsp;&nbsp; 1 - Open MyForm.<br>
&nbsp;&nbsp;&nbsp; 2 - Click at ActionButtons(inherited by BaseForm) ellipsis [...] on MyForm properties panel.<br>
&nbsp;&nbsp;&nbsp; 3 - A custom form is opened with inflated objects that I want pick. (this form is called by my CustomUITypeEditor)<br>
&nbsp;&nbsp;&nbsp; 4 - Objects that I want are picked, and I close the form. So now, the data are ok in <code>MyForm</code> and serialized into Designer.cs file. I can reopen that EditorUI clicking again in ellipsis and see objects that I picked before.<br>
&nbsp;&nbsp;&nbsp; 5 - Now when I close MyForm and reopen it, all data are lost!!! But the data still serialized into Designer.cs.
&nbsp;&nbsp;&nbsp; 6 - If I do all this steps with a <code>string</code> instead <code>List&lt;Control&gt;</code>, all are Ok.<br>
<br></p>

<p>Bellow my code:</p>

<pre><code>public class CollectionTypeEditor : UITypeEditor {

private IWindowsFormsEditorService _editorService = null;
private ICollection&lt;Control&gt; mControls = null;
private List&lt;Control&gt; mPickedControls = null;

// Editor like Modal style
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) {
  return UITypeEditorEditStyle.Modal;
}

// Opens modal and get returned data
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
  if (provider == null)
    return value;

  _editorService = (IWindowsFormsEditorService) provider
    .GetService(typeof(IWindowsFormsEditorService));

  if (_editorService == null)
    return value;

  mControls = new List&lt;Control&gt;();

  // retrieve old data
  mPickedControls = value as List&lt;Control&gt;;
  if (mPickedControls == null)
    mPickedControls = new List&lt;Control&gt;();

  // getting existent controls that will be inflated in modal
  Control mContext = (Control) context.Instance;
  GetControls(mContext);

  // open form and get response
  CollectionDesign&lt;Control&gt; frmCollections = new CollectionDesign&lt;Control&gt;(mControls, ref mPickedControls);
  var response = _editorService.ShowDialog(frmCollections);

  // returning data from editor
  return response == DialogResult.OK ? mPickedControls : value;
}
</code></pre>

<p>Everything works well here. Code for my variable in <code>BaseForm</code>. Ps.: this variable will be showed on <code>MyForm</code> where I make click at ellipsis [...] </p>

<pre><code>[Editor(typeof(CollectionTypeEditor), typeof(UITypeEditor))]
[TypeConverter(typeof(ActionButtonConverter))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List&lt;Control&gt; ActionButtons { get; set; }
</code></pre>

<p>The serialization attribute was added because the file couldn't be saved. When form is closed and reopened, all data are lost. </p>

<p>The stranger thing is that I wrote other UITypeEditor like the <strong>same way</strong>, just changing type of data to <code>string</code> and I can close or reopen my form and all works fine, the data are saved.</p>

<p>I already added a TypeConverter but I think that isn't case here. what is wrong with my code?</p>

<p>I'm getting this error on reopen form:</p>

<pre><code>Severity Code Description Project File Line Suppression State Message Method 'System.CodeDom.CodePropertyReferenceExpression.Add' not found.        
</code></pre>

<hr>

<h3>UPDATE</h3>

<p>Now my List of controls are stored in myForm.designer file when it's closed or reopened, but the controls don't are attached on property grid. i.e.: If I click on ellipsis to add a Button 'addbt' when close and reopen myForm the code is auto generated.</p>

<p>Code auto generated bellow on myForm.designer:</p>

<pre><code>  // 
  // addbt
  // 
  this.addbt.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  this.addbt.Cursor = System.Windows.Forms.Cursors.Hand;
  this.addbt.Font = new System.Drawing.Font("Tahoma", 9F);
  this.addbt.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
  this.addbt.Location = new System.Drawing.Point(13, 6);
  this.addbt.Name = "addbt";
  this.addbt.Size = new System.Drawing.Size(103, 33);
  this.addbt.TabIndex = 0;
  this.addbt.Text = "Incluir";
  this.addbt.UseVisualStyleBackColor = true;

  // 
  // myForm
  // 
  this.ActionButtons.Add(this.addbt);
</code></pre>

<p>If I make a click on ellipsis again, the data are attached to property on myForm's PropertyGrid. But when I reopen myForm, this values stored before aren't passed to property on myForm's PropertyGrid (data still stored in auto generated code designer). So when a click on the ellipsis [...] the  <code>value</code> from <code>EditValue</code> method not comes with data stored. I'm feeling that it's closer :)</p>

<p>Maybe something is wrong with my TypeConverter below:</p>

<pre><code>public class ActionButtonConverter : TypeConverter {

public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
  if (sourceType == (typeof(string)))
    return true;

  return base.CanConvertFrom(context, sourceType);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
  if(value.GetType() == typeof(string)) {
    List&lt;Control&gt; ctrs = value as List&lt;Control&gt;;

    if (ctrs != null)
      return ctrs;
  }

  return base.ConvertFrom(context, culture, value);
}


public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
  if (destinationType == typeof(string))
    return true;
  return base.CanConvertTo(context, destinationType);
}

public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
  if (value == null)
    return "null";

  if (destinationType == typeof(string))
    return "(custom collection)";

  return base.ConvertTo(context, culture, value, destinationType);
}
</code></pre>

<p>I think that I have anything error in deserialization. When myForm is reopened the ITypeDescriptorContext or value (TypeConverter) don't have anything about serialized data into designer.cs file.</p>

<p>Thanks all, and sorry for bad language :P</p>