我有一個簡單的C#Windows窗體應用程序應該顯示一個DataGridView。由於數據綁定我用了一個對象(選擇一個叫做Car類),這是什麼樣子:C# - DataGridView無法添加行?
class Car
{
public string color { get; set ; }
public int maxspeed { get; set; }
public Car (string color, int maxspeed) {
this.color = color;
this.maxspeed = maxspeed;
}
}
然而,當我在DataGridView屬性AllowUserToAddRows
設置爲true
,仍然有不小的*,讓我添加行。
有人建議將carBindingSource.AllowAdd
設置爲true
,但是,當我這樣做時,我得到MissingMethodException
其中說我的構造函數找不到。
我想你會需要一個參數少的構造函數(因爲沒有信息可以傳遞給你的2參數構造函數),那麼你怎麼綁定它? – V4Vendetta 2012-07-09 11:25:57
我不得不在我的綁定源上使用AllowNew。 – 2015-05-07 13:49:22