DataGridViewTextBoxColumn.CellTemplate Właściwość

Definicja

Pobiera lub ustawia szablon używany do modelowania wyglądu komórki.

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)>]
member this.CellTemplate : System.Windows.Forms.DataGridViewCell with get, set
Public Overrides Property CellTemplate As DataGridViewCell

Wartość właściwości

DataGridViewCell

Wszystkie DataGridViewCell pozostałe komórki w kolumnie są modelowane po.

Atrybuty

Wyjątki

Typ zestawu nie jest zgodny z typem DataGridViewTextBoxCell.

Przykłady

W poniższym przykładzie kodu pokazano użycie DataGridViewColumn.CellTemplate właściwości , która jest podobna do tej właściwości. Ten przykład jest częścią większego przykładu dostępnego w temacie How to: Manipulate Columns in the Windows Forms DataGridView Control (Jak manipulować kolumnami w kontrolce DataGridView).

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

Konstruktor klasy inicjuje DataGridViewTextBoxColumn tę właściwość do nowo utworzonego obiektu DataGridViewTextBoxCell.

Przestroga

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ż