DataGridViewComboBoxColumn.CellTemplate DataGridViewComboBoxColumn.CellTemplate DataGridViewComboBoxColumn.CellTemplate DataGridViewComboBoxColumn.CellTemplate Property


获取或设置用于创建单元格的模板。Gets or sets the template used to create cells.

 virtual property System::Windows::Forms::DataGridViewCell ^ CellTemplate { System::Windows::Forms::DataGridViewCell ^ get(); void set(System::Windows::Forms::DataGridViewCell ^ value); };
public override System.Windows.Forms.DataGridViewCell CellTemplate { get; set; }
member this.CellTemplate : System.Windows.Forms.DataGridViewCell with get, set
Public Overrides Property CellTemplate As DataGridViewCell


一个 DataGridViewCell,列中的所有其他单元格都以它为模型。A DataGridViewCell that all other cells in the column are modeled after. 默认值为新 DataGridViewComboBoxCellThe default value is a new DataGridViewComboBoxCell.


将此属性设置为非 DataGridViewComboBoxCell 类型的值时。When setting this property to a value that is not of type DataGridViewComboBoxCell.


下面的代码示例演示如何使用DataGridViewColumn.CellTemplate属性,该属性类似于此属性。The following code example demonstrates the use of the DataGridViewColumn.CellTemplate property, which is similar to this property. 此示例摘自了如何:操作 Windows 窗体 DataGridView 控件中的列。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 =
    DataGridViewCell cell = new DataGridViewTextBoxCell();

    cell.Style.BackColor = Color.Wheat;
    column.CellTemplate = cell;
Private Sub CustomizeCellsInThirdColumn()

    Dim thirdColumn As Integer = 2
    Dim column As DataGridViewColumn = _
    Dim cell As DataGridViewCell = _
        New DataGridViewTextBoxCell()

    cell.Style.BackColor = Color.Wheat
    column.CellTemplate = cell
End Sub


DataGridViewComboBoxColumn类的构造函数将此属性初始化为新创建DataGridViewComboBoxCell的。The constructor for the DataGridViewComboBoxColumn class initializes this property to a newly created DataGridViewComboBoxCell.


更改单元格模板的属性不会立即影响列现有单元的用户界面(UI)。Changing the properties of the cell template will not immediately affect the user interface (UI) of the column's existing cells. 这些更改仅在重新生成列后才明显(例如,通过对列进行排序或通过调用DataGridView.InvalidateColumn方法)。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).