DataGridViewTextBoxColumn.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 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

属性值

DataGridViewCell

一个 DataGridViewCell,列中的所有其他单元格都以它为模型。

属性

例外

所设置的类型与类型 DataGridViewTextBoxCell 不兼容。

示例

下面的代码示例演示了该属性的使用 DataGridViewColumn.CellTemplate ,该属性类似于此属性。 此示例是“如何:操作 Windows 窗体 DataGridView 控件中的列”中提供的大型示例的一部分。

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

注解

类的 DataGridViewTextBoxColumn 构造函数将此属性初始化为新创建的 DataGridViewTextBoxCell

注意

更改单元格模板的属性不会立即影响列现有单元格的用户界面 (UI) 。 这些更改仅在列重新生成 (之后才明显,例如,通过对列进行排序或通过对方法) 的 DataGridView.InvalidateColumn 调用。

适用于

另请参阅