DataGridViewCheckBoxColumn.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 override System.Windows.Forms.DataGridViewCell CellTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.CellTemplate : System.Windows.Forms.DataGridViewCell with get, set
Public Overrides Property CellTemplate As DataGridViewCell

屬性值

DataGridViewCell

DataGridViewCell,做為資料欄中所有其他儲存格的模型。 預設值是新的 DataGridViewCheckBoxCell 執行個體。

屬性

例外狀況

此屬性會設定為不是型別 DataGridViewCheckBoxCell 的值。

範例

下列程式碼範例示範如何使用 DataGridViewCheckBoxColumn 來標記哪些員工不在辦公室。 儲存格範本是用來將相同的色彩套用至核取方塊資料行中的所有儲存格。 這個範例是類別概觀主題中較大範例的 DataGridViewComboBoxColumn 一部分。

private:
    void AddOutOfOfficeColumn()
    {
        DataGridViewCheckBoxColumn^ column = gcnew DataGridViewCheckBoxColumn();
        {
            column->HeaderText = ColumnName::OutOfOffice.ToString();
            column->Name = ColumnName::OutOfOffice.ToString();
            column->AutoSizeMode = 
                DataGridViewAutoSizeColumnMode::DisplayedCells;
            column->FlatStyle = FlatStyle::Standard;
            column->ThreeState = true;
            column->CellTemplate = gcnew DataGridViewCheckBoxCell();
            column->CellTemplate->Style->BackColor = Color::Beige;
        }

        DataGridView1->Columns->Insert(0, column);
    }
private void AddOutOfOfficeColumn()
{
    DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
    {
        column.HeaderText = ColumnName.OutOfOffice.ToString();
        column.Name = ColumnName.OutOfOffice.ToString();
        column.AutoSizeMode = 
            DataGridViewAutoSizeColumnMode.DisplayedCells;
        column.FlatStyle = FlatStyle.Standard;
        column.ThreeState = true;
        column.CellTemplate = new DataGridViewCheckBoxCell();
        column.CellTemplate.Style.BackColor = Color.Beige;
    }

    DataGridView1.Columns.Insert(0, column);
}
Private Sub AddOutOfOfficeColumn()
    Dim column As New DataGridViewCheckBoxColumn()
    With column
        .HeaderText = ColumnName.OutOfOffice.ToString()
        .Name = ColumnName.OutOfOffice.ToString()
        .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
        .FlatStyle = FlatStyle.Standard
        .CellTemplate = New DataGridViewCheckBoxCell()
        .CellTemplate.Style.BackColor = Color.Beige
    End With

    DataGridView1.Columns.Insert(0, column)
End Sub

備註

類別的建構函式會將 DataGridViewCheckBoxColumn 這個屬性初始化為新建立的 DataGridViewCheckBoxCell

警告

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

適用於

另請參閱