Please consider my codes below:
I’m getting an error Constructor on type 'System.String' not found. when I add new string to the collection using the PropertyGrid control.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
propertyGrid1.SelectedObject = Class1.Instance.StringCollection;
}
}
-----------------------------------------------------------------------------
public sealed class Class1
{
private static Class1 _instance = new Class1();
private List<string> _stringListCollection = new List<string>();
public Class1()
{
}
public static Class1 Instance
{
get { return _instance; }
}
public List<string> StringCollection
{
get { return _stringListCollection; }
set { _stringListCollection = value; }
}
}
When you assign List of something to PropertyGrid, it tries to show single row with modify
...button,where default modify dialog require Item class to have default constructor, which is not right in case of string
You can create class with default constructor and string property in it, and assign a collection of that class instead of string
Or you can use EditorAttribute to override default editor
Hope this helps