DataGridViewColumn.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 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

Значение свойства

А DataGridViewCell все остальные ячейки в столбце моделиируются после. Значение по умолчанию — null.

Атрибуты

Примеры

В следующем примере кода показано, как использовать DataGridViewCell его в качестве шаблона.DataGridViewColumn Изменения стиля, внесенные в любую ячейку в столбце, влияют на все ячейки столбца. Этот пример кода является частью более крупного примера, предоставленного для DataGridViewColumn класса.

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

Комментарии

Конструкторы для DataGridViewColumn класса инициализировать это свойство. Конструктор без параметров задает для свойства nullзначение; другой конструктор копирует шаблон ячейки из его параметра.

Note

Изменение свойств шаблона ячейки не повлияет на пользовательский интерфейс существующих ячеек столбца. Эти изменения очевидны только после повторного создания столбца (например, путем сортировки столбца или вызова DataGridView.InvalidateColumn метода).

Применяется к

См. также раздел