DataGridViewLinkColumn.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,做為資料欄中所有其他儲存格的模型。 預設值是新的 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) 。

適用於

另請參閱