DataGridViewColumn.CellTemplate Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur templat yang digunakan untuk membuat sel baru.
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, set
Public Overridable Property CellTemplate As DataGridViewCell
Nilai Properti
Bahwa DataGridViewCell semua sel lain dalam kolom dimodelkan setelahnya. Defaultnya adalah null.
- Atribut
Contoh
Contoh kode berikut menunjukkan cara menggunakan DataGridViewCell sebagai templat untuk DataGridViewColumn. Perubahan gaya yang dibuat pada sel mana pun dalam kolom memengaruhi semua sel kolom. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk DataGridViewColumn kelas .
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
Keterangan
Konstruktor untuk DataGridViewColumn kelas menginisialisasi properti ini. Konstruktor tanpa parameter mengatur properti ke null; konstruktor lain menyalin templat sel dari parameternya.
Note
Mengubah properti templat sel tidak akan segera memengaruhi antarmuka pengguna (UI) dari sel kolom yang ada. Perubahan ini hanya jelas setelah kolom diregenerasi (misalnya, dengan mengurutkan kolom atau melalui panggilan ke DataGridView.InvalidateColumn metode ).