DataGridViewColumn.CellTemplate Właściwość

Definicja

Pobiera lub ustawia szablon używany do tworzenia nowych komórek.

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

Wartość właściwości

Wszystkie DataGridViewCell pozostałe komórki w kolumnie są modelowane po. Wartość domyślna to null.

Atrybuty

Przykłady

W poniższym przykładzie kodu pokazano, jak używać elementu DataGridViewCell jako szablonu dla elementu DataGridViewColumn. Zmiany stylu wprowadzone w dowolnej komórce w kolumnie wpływają na wszystkie komórki kolumny. Ten przykład kodu jest częścią większego przykładu udostępnionego DataGridViewColumn dla klasy .

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

Uwagi

Konstruktory klasy inicjują DataGridViewColumn tę właściwość. Konstruktor bez parametrów ustawia właściwość na null; inny konstruktor kopiuje szablon komórki z jego parametru.

Uwaga

Zmiana właściwości szablonu komórki nie wpłynie natychmiast na interfejs użytkownika (UI) istniejących komórek kolumny. Te zmiany są widoczne tylko po wygenerowaniu kolumny (na przykład przez posortowanie kolumny lub wywołanie DataGridView.InvalidateColumn metody).

Dotyczy

Zobacz też