User Interface Reference for Windows Forms 
String Collection Editor 

Enables you to view and change the list of strings for controls such as list boxes and combo boxes. Display this editor from the Properties window by clicking the Ellipsis (VisualStudioEllipsesButton screenshot) button next to the Items property of the control.

Enter the strings in the collection

Lists the strings in the collection. Each line of text is considered to be an individual string.

See Also

Tags :


Community Content

DaveyM69
Problems with the String Collection Editor

SOLUTION:

The correct, and confirmed working, attribute you must decorate your string collection property with is:

[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]

UPDATE:

What appears to be the "String Collection Editor" (as that is the title on the form) may not be. From my research, the string collection editor should appear as a very simple single column form. The "String Collection Editor" opened by the property grid is a two column form, with a listbox on the left and another property grid on the right.

Apparently there are issues with the String Collection Editor and the PropertyGrid in version 2.0.50727 of the framework. Specifically, when attempting to add a string to the collection (by pressing the Add button) the following error message is displayed:

---------------------------
Error
---------------------------
Constructor on type 'System.String' not found.
---------------------------
OK
---------------------------

There are many requests for help with this issue, all of which suggest that adding an EditorAttribute to the collection property of the object being edited in the property grid. These are along the lines of:

[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]

This does not appear to solve the problem, as the correct editor is being created (the String Collection Editor), but the editor appears to be unable to create new instances of System.String.

If anyone monitoring this has any ideas, please add your comments here. I will return and edit this when I have found a workable solution.

Code to play with:

   Create a class and add the following code:
  
public sealed class StringCollectionFailure
{
private StringCollection fail = new StringCollection();
private string name = string.Empty;
public string Name { get { return name; } set { name = value; } }
public StringCollection Failures { get { return fail; } }
}
    
   Create a form, add a property grid to it, and add the following code after InitializeComponents in the load event handler:
  
StringCollectionFailure fail = new StringCollectionFailure();
fail.Name = "I will fail!";
fail.Failures.Add("Yes, sir!");
               this.propertyGrid1.SelectedObject = fail;
  

This works for me:

[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design", typeof(UITypeEditor))]

Dave

Tags : contentbug

Page view tracker