我正在做一個項目,我需要添加一個字段(我們稱之爲字段)到DataGridView單元格。這一點是爲了能夠在DataGriidView單元格中添加一個額外的字段,這將使項目的其餘部分更加容易。自定義datagridview單元格?
我創建了以下內容:
public class CustomGridRow:DataGridRow{}
public class CustomGridColumn:DataGridViewColumn
{
public CustomGridColumn
{
This.TemplateCell = new CustomGridTextBoxCell()
}
}
public class CustomGridTextBoxCell: DataGridViewTextBoxCell
{
public string field;
}
問題: 如果我創建像一個類(這是我想達到的目標):
public class CustomGridCell: DataGridViewCell{}
而且場移到CustomGridCell
,我希望CustomGridTextBoxCell
繼承自新的CustomGridCell
,但它已經有一個基類DataGridViewCell
和C#不允許類繼承兩個基類。
我的理解是通過Interfaces
來解決嗎?任何想法如何解決?
難道你不能使用抽象類,然後創建一個繼承自它的具體類嗎? – sr28
你能說明一個答案嗎? @ sr28 –