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

屬性值

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

例外狀況

此集合型別與型別 DataGridViewImageCell 不相容。The set type is not compatible with type DataGridViewImageCell.

範例

下列程式碼範例示範DataGridViewColumn.CellTemplate屬性的用法, 這類似于此屬性。The following code example demonstrates the use of the DataGridViewColumn.CellTemplate property, which is similar to this property. 這個範例是中所提供之較大範例的一部分。操控 Windows Forms DataGridView 控制項中的資料行。This example is part of a larger example available in How to: Manipulate Columns in the Windows Forms DataGridView Control.

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

備註

類別的函式會將此屬性初始化為新建立DataGridViewImageCell的。 DataGridViewImageColumnThe constructors for the DataGridViewImageColumn class initialize this property to a newly created DataGridViewImageCell.

警告

變更資料格範本的屬性並不會立即影響資料行現有資料格的使用者介面 (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).

適用於

另請參閱