DataGridViewImageColumn.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, set
Public Overrides Property CellTemplate As DataGridViewCell
屬性值
DataGridViewCell A,欄位中所有其他儲存格皆以之為模型。
- 屬性
例外狀況
集合型別與型別 DataGridViewImageCell不相容。
範例
以下程式碼範例展示了該性質的使用 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
備註
該類別的 DataGridViewImageColumn 構造子會將此屬性初始化為新建立 DataGridViewImageCell的 。
謹慎
更改儲存格範本的屬性不會立即影響該欄位現有儲存格的使用者介面(UI)。 這些變化只有在欄位重新生成後才會顯現(例如透過排序欄位或透過呼叫 DataGridView.InvalidateColumn 方法)。