DataGridViewColumn.CellTemplate Vlastnost

Definice

Získá nebo nastaví šablonu použitou k vytvoření nových buněk.

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

Hodnota vlastnosti

Hodnota, DataGridViewCell podle které jsou modelovány všechny ostatní buňky ve sloupci. Výchozí formát je null.

Atributy

Příklady

Následující příklad kódu ukazuje, jak použít DataGridViewCell jako šablonu pro DataGridViewColumn. Změny stylu provedené v libovolné buňce ve sloupci ovlivní všechny buňky sloupce. Tento příklad kódu je součástí většího příkladu DataGridViewColumn pro třídu .

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

Poznámky

Konstruktory třídy DataGridViewColumn inicializují tuto vlastnost. Konstruktor bez parametrů nastaví vlastnost na null; druhý konstruktor zkopíruje šablonu buňky ze svého parametru.

Poznámka

Změna vlastností šablony buňky nebude mít okamžitý vliv na uživatelské rozhraní existujících buněk sloupce. Tyto změny se projeví až po opětovném vygenerování sloupce (například řazením sloupce nebo voláním DataGridView.InvalidateColumn metody ).

Platí pro

Viz také