請考慮下面的代碼我:一個PropertyGrid的問題
我得到一個錯誤Constructor on type 'System.String' not found.
當我添加新的字符串使用PropertyGrid
控制集合。
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; }
}
}
您的代碼不正確。您可能已將'Class1.Instance'分配給屬性網格。通過分配'Class1.Instance',然後在'StringCollection'前面按下'''',然後按下Add按鈕,你會得到你提到的錯誤。 – 2012-02-02 09:02:05
提供的代碼沒有編譯出於以下兩個原因:實例沒有指定類型,因爲沒有聲明名爲Instance的類。我假設它應該被鍵入Class1。其次名爲Form1的事件處理程序是非法的,因爲一個方法不能具有與它的封閉類型相同的名稱。我將其更改爲Form1_Load,並根據事件處理程序中的代碼將其分配給Load事件。 – Crippledsmurf 2012-02-02 09:07:47
對不起,請大家諒解。這不是我的實際代碼,它更可能只是一個僞代碼.. :) – yonan2236 2012-02-02 09:14:53