Поделиться через


DataGridViewComboBoxColumn.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)]
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 все остальные ячейки в столбце моделиируются после. Значение по умолчанию является новым DataGridViewComboBoxCell.

Атрибуты

Исключения

При задании этого свойства значение, которое не является типом DataGridViewComboBoxCell.

Примеры

В следующем примере кода демонстрируется использование DataGridViewColumn.CellTemplate свойства, аналогичного этому свойству. Этот пример является частью более крупного примера, доступного в разделе "Практическое руководство. Управление столбцами в элементе управления DataGridView в Windows Forms".

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

Комментарии

Конструктор класса DataGridViewComboBoxColumn инициализирует это свойство в только что созданное.DataGridViewComboBoxCell

Предостережение

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

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

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