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設定します。もう 1 つのコンストラクターは、そのパラメーターからセル テンプレートをコピーします。

注意

セル テンプレートのプロパティを変更すると、列の既存のセルのユーザー インターフェイス (UI) にすぐには影響しません。 これらの変更は、列が再生成された後にのみ明らかになります (たとえば、列の並べ替えやメソッドの DataGridView.InvalidateColumn 呼び出しによる)。

適用対象

こちらもご覧ください