DataGridViewColumn.CellTemplate DataGridViewColumn.CellTemplate DataGridViewColumn.CellTemplate DataGridViewColumn.CellTemplate Property

定義

取得或設定用來建立新儲存格的樣板。Gets or sets the template used to create new cells.

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; }
member this.CellTemplate : System.Windows.Forms.DataGridViewCell with get, set
Public Overridable Property CellTemplate As DataGridViewCell

屬性值

DataGridViewCell,做為資料欄中所有其他儲存格的模型。A DataGridViewCell that all other cells in the column are modeled after. 預設為 nullThe default is null.

範例

下列程式碼範例示範如何使用DataGridViewCell做為的範本。 DataGridViewColumnThe following code example demonstrates how to use a DataGridViewCell as a template for a DataGridViewColumn. 對資料行中的任何資料格所做的樣式變更,會影響資料行的所有資料格。Style changes made to any cell in the column affect all of the column's cells. 這個程式碼範例是針對DataGridViewColumn類別提供之較大範例的一部分。This code example is part of a larger example provided for the DataGridViewColumn class.

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類別的函式會初始化這個屬性。The constructors for the DataGridViewColumn class initialize this property. 無參數的函式會將null屬性設定為; 另一個函式會從其參數複製資料格範本。The parameterless constructor sets the property to null; the other constructor copies the cell template from its parameter.

注意

變更資料格範本的屬性並不會立即影響資料行現有資料格的使用者介面(UI)。Changing the properties of the cell template will not immediately affect the user interface (UI) of the column's existing cells. 這些變更只有在資料行重新產生之後才會明顯(例如,藉由排序資料行或透過呼叫DataGridView.InvalidateColumn方法)。These changes are only apparent after the column is regenerated (for example, by sorting the column or through a call to the DataGridView.InvalidateColumn method).

適用於

另請參閱