DataGridViewLinkColumn.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)>]
member this.CellTemplate : System.Windows.Forms.DataGridViewCell with get, setPublic Overrides Property CellTemplate As DataGridViewCell属性值
一个 DataGridViewCell,列中的所有其他单元格都以它为模型。 默认值为新 DataGridViewLinkCell 实例。
- 属性
例外
将此属性设置为非 DataGridViewLinkCell 类型的值时。
示例
下面的代码示例演示如何使用 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
注解
类的 DataGridViewLinkColumn 构造函数将此属性初始化为新创建的 DataGridViewLinkCell。
注意
更改单元格模板的属性不会立即影响列现有单元格的用户界面 (UI) 。 仅当列重新生成 (后,这些更改才明显,例如,通过对方法) 的调用对列进行排序或调用 DataGridView.InvalidateColumn 。