DataGridViewButtonColumn.CellTemplate Egenskap

Definition

Hämtar eller anger mallen som används för att skapa nya celler.

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)]
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

Egenskapsvärde

A DataGridViewCell som alla andra celler i kolumnen modelleras efter.

Attribut

Undantag

Det angivna värdet när du anger den här egenskapen kunde inte omvandlas till en DataGridViewButtonCell.

Exempel

Följande kodexempel visar hur du använder en DataGridViewButtonColumn för att visa den försäljning som en anställd har gjort. En cellmall används för att tillämpa samma färg på alla knappar. Det här exemplet är en del av ett större exempel som är tillgängligt i DataGridViewComboBoxColumn avsnittet klassöversikt.

private:
    void AddButtonColumn()
    {
        DataGridViewButtonColumn^ buttons = gcnew DataGridViewButtonColumn();
        {
            buttons->HeaderText = "Sales";
            buttons->Text = "Sales";
            buttons->UseColumnTextForButtonValue = true;
            buttons->AutoSizeMode =
                DataGridViewAutoSizeColumnMode::AllCells;
            buttons->FlatStyle = FlatStyle::Standard;
            buttons->CellTemplate->Style->BackColor = Color::Honeydew;
            buttons->DisplayIndex = 0;
        }

        DataGridView1->Columns->Add(buttons);

    }
private void AddButtonColumn()
{
    DataGridViewButtonColumn buttons = new DataGridViewButtonColumn();
    {
        buttons.HeaderText = "Sales";
        buttons.Text = "Sales";
        buttons.UseColumnTextForButtonValue = true;
        buttons.AutoSizeMode =
            DataGridViewAutoSizeColumnMode.AllCells;
        buttons.FlatStyle = FlatStyle.Standard;
        buttons.CellTemplate.Style.BackColor = Color.Honeydew;
        buttons.DisplayIndex = 0;
    }

    DataGridView1.Columns.Add(buttons);
}
Private Sub AddButtonColumn()
    Dim buttons As New DataGridViewButtonColumn()
    With buttons
        .HeaderText = "Sales"
        .Text = "Sales"
        .UseColumnTextForButtonValue = True
        .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
        .FlatStyle = FlatStyle.Standard
        .CellTemplate.Style.BackColor = Color.Honeydew
        .DisplayIndex = 0
    End With

    DataGridView1.Columns.Add(buttons)

End Sub

Kommentarer

Konstruktorn för DataGridViewButtonColumn klassen initierar den här egenskapen till en nyligen skapad DataGridViewButtonCell.

Caution

Om du ändrar egenskaperna för cellmallen påverkas inte omedelbart användargränssnittet (UI) för kolumnens befintliga celler. Dessa ändringar visas bara när kolumnen har återskapats (till exempel genom att sortera kolumnen eller genom ett anrop till DataGridView.InvalidateColumn metoden).

Gäller för

Se även