DataGridViewComboBoxColumn.CellTemplate Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the template used to create cells.
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
Property Value
A DataGridViewCell that all other cells in the column are modeled after. The default value is a new DataGridViewComboBoxCell.
- Attributes
Exceptions
When setting this property to a value that is not of type DataGridViewComboBoxCell.
Examples
The following code example demonstrates the use of the DataGridViewColumn.CellTemplate property, which is similar to this property. This example is part of a larger example available in How to: Manipulate Columns in the Windows Forms DataGridView Control.
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
Remarks
The constructor for the DataGridViewComboBoxColumn class initializes this property to a newly created DataGridViewComboBoxCell.
Caution
Changing the properties of the cell template will not immediately affect the user interface (UI) of the column's existing cells. These changes are only apparent after the column is regenerated (for example, by sorting the column or through a call to the DataGridView.InvalidateColumn method).