DataGridViewColumn.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 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, setPublic 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;另一个构造函数从其 参数复制单元格模板。
注意
更改单元格模板的属性不会立即影响用户界面 (UI) 列的现有单元格。 只有在重新生成列后,这些更改才明显 (例如,通过对列进行排序或通过 DataGridView.InvalidateColumn 调用方法) 。