DataGridViewColumn.CellTemplate 屬性

定義

取得或設定用來建立新儲存格的樣板。

public:
 virtual property System::Windows::Forms::DataGridViewCell ^ CellTemplate { System::Windows::Forms::DataGridViewCell ^ get(); void set(System::Windows::Forms::DataGridViewCell ^ value); };
[System.ComponentModel.Browsable(false)]
public virtual System.Windows.Forms.DataGridViewCell CellTemplate { get; set; }
[System.ComponentModel.Browsable(false)]
public virtual System.Windows.Forms.DataGridViewCell? CellTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.CellTemplate : System.Windows.Forms.DataGridViewCell with get, set
Public Overridable Property CellTemplate As DataGridViewCell

屬性值

DataGridViewCell,做為資料欄中所有其他儲存格的模型。 預設為 null

屬性

範例

下列程式碼範例示範如何使用 DataGridViewCell 做為 的 DataGridViewColumn 範本。 對資料行中任何儲存格所做的樣式變更會影響所有資料行的儲存格。 此程式碼範例是提供給 類別之較大範例的 DataGridViewColumn 一部分。

void CustomizeCellsInThirdColumn()
{
   int thirdColumn = 2;
   DataGridViewColumn^ column = dataGridView->Columns[ thirdColumn ];
   DataGridViewCell^ cell = gcnew DataGridViewTextBoxCell;
   cell->Style->BackColor = Color::Wheat;
   column->CellTemplate = cell;
}
private void CustomizeCellsInThirdColumn()
{
    int thirdColumn = 2;
    DataGridViewColumn column =
        dataGridView.Columns[thirdColumn];
    DataGridViewCell cell = new DataGridViewTextBoxCell();

    cell.Style.BackColor = Color.Wheat;
    column.CellTemplate = cell;
}
Private Sub CustomizeCellsInThirdColumn()

    Dim thirdColumn As Integer = 2
    Dim column As DataGridViewColumn = _
        dataGridView.Columns(thirdColumn)
    Dim cell As DataGridViewCell = _
        New DataGridViewTextBoxCell()

    cell.Style.BackColor = Color.Wheat
    column.CellTemplate = cell
End Sub

備註

類別的建構函式會 DataGridViewColumn 初始化這個屬性。 無參數建構函式會將 屬性設定為 null ;其他建構函式會從其 參數複製資料格範本。

注意

變更儲存格範本的屬性不會立即影響資料行現有儲存格的使用者介面 (UI) 。 這些變更只有在重新產生資料行 (之後才會明顯,例如,藉由排序資料行或透過呼叫 DataGridView.InvalidateColumn 方法) 。

適用於

另請參閱