DataGridViewComboBoxColumn.CellTemplate 属性       
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置用于创建单元格的模板。
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, setPublic Overrides Property CellTemplate As DataGridViewCell属性值
一个 DataGridViewCell,列中的所有其他单元格都以它为模型。 默认值为新 DataGridViewComboBoxCell。
- 属性
例外
将此属性设置为非 DataGridViewComboBoxCell 类型的值时。
示例
下面的代码示例演示如何使用 DataGridViewColumn.CellTemplate 属性,该属性类似于此属性。 此示例是 DataGridView 控件中如何:操作列Windows 窗体中提供的更大示例的一部分。
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。
注意
更改单元格模板的属性不会立即影响用户界面 (UI) 列的现有单元格。 只有在重新生成列后,这些更改才明显 (例如,通过对列进行排序或通过调用 DataGridView.InvalidateColumn 方法) 。